Add persistent data storage to your Week 5 Lab using the MyS
Add persistent data storage to your Week 5 Lab using the MySQL Database. PROBLEM: Stocks4U Portfolio Management System
The portfolio management system you developed for Stocks4U needs the ability to save and restore a user’s data from a MySql Database.
FUNCTIONAL REQUIREMENTS The functional requirements of the Stocks4U application have not changed, and the Graphical User Interface has not changed from Week 5. StockIO class Modify the StockIO class to read and write the stock information to and from a MySQL database. Called “StocksDB” This class should have two methods.
getData—reads data from file, returns data in array list of stock objects
saveData—writes data from an array list to the data base in proper format
deleteStock—deletes the identified stock from the database
updateStock—updates the identified stock in the database. The database connection string will be stored as a constant in the StockIO class.
GUI class Note that you will need to add an ArrayList to your GUI class to manage the data to/from the file. It will act as a parallel array to your DefaultListModel. Any time you add a stock, you must add it in BOTH places.
Any time you remove a stock, you must remove it in BOTH places.
File—open should open the database, retrieve the existing records and display the existing records.
File—save should save all records, new and old, back to the database.
File—exit should exit the program. The total value of the portfolio should be displayed at all times and updated anytime a stock is added or removed.
//Stock.java class
public class Stock {
private String companyName;
private int numberShares;
private double purchasePrice;
private double currentPrice;
public Stock() { }
public Stock(String[] s)
{
try {
setCompanyName(s[0]);
setNumberShares(Integer.parseInt(s[1].trim()));
setPurchasePrice(Double.parseDouble(s[3].trim()));
setCurrentPrice(Double.parseDouble(s[2].trim()));
} catch (Exception e) { throw e;
}
}
public Stock(String sName, int nShares, double pPrice, double cPrice)
{
setCompanyName(sName); setNumberShares(nShares);
setPurchasePrice(pPrice); setCurrentPrice(cPrice);
}
public void setCompanyName(String cName) {
this.companyName = cName;
}
public String getCompanyName() {
return companyName;
}
public void setNumberShares(int numberShares) {
this.numberShares = numberShares;
}
public int getNumberShares() {
return numberShares;
}
public void setPurchasePrice(double purchasePrice) {
this.purchasePrice = purchasePrice;
} public double getPurchasePrice() {
return purchasePrice;
}
public void setCurrentPrice(double currentPrice)
{
this.currentPrice = currentPrice;
} public double getCurrentPrice() { return currentPrice; }
/** * * @return the profit or loss */
public double getProfitOrLoss() {
return numberShares * (currentPrice - purchasePrice); }
/** * * @return stock name */
public String toString() {
return companyName; } }
//StockGUI.java class
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
/** * * @author Amit Ranga */
public class StockGUI extends javax.swing.JFrame {
/** * Create new form Stocks4U */
public StockGUI() {
initComponents();
stockListGUI.setModel(new DefaultListModel());
}
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */
@SuppressWarnings(\"unchecked\") //
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
/**
*
* @author Amit Ranga
*/
public class StockGUI extends javax.swing.JFrame {
/**
* Create new form Stocks4U
*/
public StockGUI() {
initComponents();
stockListGUI.setModel(new DefaultListModel());
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings(\"unchecked\")
// <editor-fold defaultstate=\"collapsed\" desc=\"Generated Code\">
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
tabbedPane = new javax.swing.JTabbedPane();
listTab = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
stockListGUI = new javax.swing.JList<>();
stockInfo = new javax.swing.JLabel();
removeStockButton = new javax.swing.JButton();
totalValueLabel = new javax.swing.JLabel();
addStockTab = new javax.swing.JPanel();
stockNameLabel = new javax.swing.JLabel();
stockNameTextField = new javax.swing.JTextField();
quantityLabel = new javax.swing.JLabel();
quantityTextField = new javax.swing.JTextField();
purchasePriceLabel = new javax.swing.JLabel();
purchasePriceTextField = new javax.swing.JTextField();
currentPriceLabel = new javax.swing.JLabel();
currentPriceTextField = new javax.swing.JTextField();
addStockButton = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
openMenuItem = new javax.swing.JMenuItem();
saveMenuItem = new javax.swing.JMenuItem();
exitMenuItem = new javax.swing.JMenuItem();
jTextField1.setText(\"jTextField1\");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(\"Portofolio Management\");
stockListGUI.setBackground(new java.awt.Color(240, 240, 240));
stockListGUI.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
stockListGUIMouseClicked(evt);
}
});
jScrollPane1.setViewportView(stockListGUI);
stockInfo.setText(\"Stock Information\");
removeStockButton.setText(\"Remove Stock\");
removeStockButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeStockButtonActionPerformed(evt);
}
});
totalValueLabel.setText(\"Total Value: \");
javax.swing.GroupLayout listTabLayout = new javax.swing.GroupLayout(listTab);
listTab.setLayout(listTabLayout);
listTabLayout.setHorizontalGroup(
listTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, listTabLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(removeStockButton)
.addGap(145, 145, 145))
.addGroup(listTabLayout.createSequentialGroup()
.addGroup(listTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(stockInfo)
.addComponent(totalValueLabel))
.addGap(0, 0, Short.MAX_VALUE))
);
listTabLayout.setVerticalGroup(
listTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(listTabLayout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(stockInfo)
.addGap(18, 18, 18)
.addComponent(removeStockButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
.addComponent(totalValueLabel)
.addContainerGap())
);
tabbedPane.addTab(\"List\", listTab);
stockNameLabel.setText(\"Stock name\");
quantityLabel.setText(\"Quantity\");
purchasePriceLabel.setText(\"Purchase price\");
currentPriceLabel.setText(\"Current price\");
addStockButton.setText(\"Add Stock\");
addStockButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addStockButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout addStockTabLayout = new javax.swing.GroupLayout(addStockTab);
addStockTab.setLayout(addStockTabLayout);
addStockTabLayout.setHorizontalGroup(
addStockTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, addStockTabLayout.createSequentialGroup()
.addContainerGap(66, Short.MAX_VALUE)
.addGroup(addStockTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(stockNameLabel)
.addComponent(quantityLabel)
.addComponent(purchasePriceLabel)
.addComponent(currentPriceLabel))
.addGap(34, 34, 34)
.addGroup(addStockTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(addStockButton)
.addGroup(addStockTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(stockNameTextField)
.addComponent(quantityTextField)
.addComponent(purchasePriceTextField)
.addComponent(currentPriceTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)))
.addGap(38, 38, 38))
);
addStockTabLayout.setVerticalGroup(
addStockTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(addStockTabLayout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(addStockTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(stockNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(stockNameLabel))
.addGap(18, 18, 18)
.addGroup(addStockTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(quantityLabel)
.addComponent(quantityTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(25, 25, 25)
.addGroup(addStockTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(purchasePriceLabel)
.addComponent(purchasePriceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(addStockTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(currentPriceLabel)
.addComponent(currentPriceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addComponent(addStockButton)
.addContainerGap(63, Short.MAX_VALUE))
);
tabbedPane.addTab(\"Add Stock\", addStockTab);
jMenu1.setText(\"File\");
openMenuItem.setText(\"Open\");
openMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openMenuItemActionPerformed(evt);
}
});
jMenu1.add(openMenuItem);
saveMenuItem.setText(\"Save\");
saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveMenuItemActionPerformed(evt);
}
});
jMenu1.add(saveMenuItem);
exitMenuItem.setText(\"Exit\");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
jMenu1.add(exitMenuItem);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tabbedPane)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tabbedPane, javax.swing.GroupLayout.Alignment.TRAILING)
);
pack();
}// </editor-fold>
private void removeStockButtonActionPerformed(java.awt.event.ActionEvent evt) {
int index = stockListGUI.getSelectedIndex(); // get selected index
if (0 <= index && index < stockListGUI.getModel().getSize()) {
DefaultListModel model = (DefaultListModel) stockListGUI.getModel(); // get model
model.remove(index); // remove stock from GUI
stockList.remove(index); // remove stock from list
}
}
private void addStockButtonActionPerformed(java.awt.event.ActionEvent evt) {
String stockName = stockNameTextField.getText(); // get name
int quantity = 0;
boolean isError = false;
try {
// get quantity
quantity = Integer.parseInt(quantityTextField.getText());
} catch (Exception e) {
isError = true;
JOptionPane.showMessageDialog(null, \"Invalid quantity, please try again!!!\", \"Error\", JOptionPane.ERROR_MESSAGE);
}
double purchasePrice = 0;
try {
// get purchase price
purchasePrice = Double.parseDouble(purchasePriceTextField.getText());
} catch (Exception e) {
isError = true;
JOptionPane.showMessageDialog(null, \"Invalid Purchase price, please try again!!!\", \"Error\", JOptionPane.ERROR_MESSAGE);
}
double currentPrice = 0;
try {
// get curretn price
currentPrice = Double.parseDouble(currentPriceTextField.getText());
} catch (Exception e) {
isError = true;
JOptionPane.showMessageDialog(null, \"Invalid Current price, please try again!!!\", \"Error\", JOptionPane.ERROR_MESSAGE);
}
if (!isError) {
((DefaultListModel) stockListGUI.getModel()).addElement(stockName + \": \" + quantity + \" shares\");
stockList.add(new Stock(stockName, quantity, purchasePrice, currentPrice)); // add a new stock
}
}
private void stockListGUIMouseClicked(java.awt.event.MouseEvent evt) {
int index = stockListGUI.getSelectedIndex(); // get selected index
if (0 <= index && index < stockListGUI.getModel().getSize()) {
Stock stock = stockList.get(index);
double value = stock.getProfitOrLoss();
if (value >= 0) {
stockInfo.setText(stock.getCompanyName() + \": Profit of $\" + value);
} else {
stockInfo.setText(stock.getCompanyName() + \": Loss of $\" + value);
}
total = stock.getNumberShares() * stock.getPurchasePrice();
totalValueLabel.setText(\"Total Value: $\" + total);
}
}
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// exit program
System.exit(0);
}
private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
String fileName = JOptionPane.showInputDialog(\"Enter filename\");
try {
StockIO io = new StockIO(fileName);
stockList = io.getData();
((DefaultListModel) stockListGUI.getModel()).clear();
for (Stock stock: stockList) {
((DefaultListModel) stockListGUI.getModel()).addElement(stock.getCompanyName() + \": \" + stock.getNumberShares() + \" shares\");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.toString(), \"Error\", JOptionPane.ERROR_MESSAGE);
}
}
private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
String fileName = JOptionPane.showInputDialog(\"Enter filename\");
try {
StockIO io = new StockIO(fileName);
io.saveData(stockList);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.toString(), \"Error\", JOptionPane.ERROR_MESSAGE);
}
}
public boolean existFile(String filePathString) {
File f = new File(filePathString);
if(f.exists() && !f.isDirectory()) {
return true;
}
return false;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate=\"collapsed\" desc=\" Look and feel setting code (optional) \">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if (\"Nimbus\".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(StockGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(StockGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(StockGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(StockGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new StockGUI().setVisible(true);
}
});
}
private double total = 0;
private List<Stock> stockList = new ArrayList<Stock>();
private DefaultListModel model = new DefaultListModel();
// Variables declaration - do not modify
private javax.swing.JButton addStockButton;
private javax.swing.JPanel addStockTab;
private javax.swing.JLabel currentPriceLabel;
private javax.swing.JTextField currentPriceTextField;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField1;
private javax.swing.JPanel listTab;
private javax.swing.JMenuItem openMenuItem;
private javax.swing.JLabel purchasePriceLabel;
private javax.swing.JTextField purchasePriceTextField;
private javax.swing.JLabel quantityLabel;
private javax.swing.JTextField quantityTextField;
private javax.swing.JButton removeStockButton;
private javax.swing.JMenuItem saveMenuItem;
private javax.swing.JLabel stockInfo;
private javax.swing.JList<String> stockListGUI;
private javax.swing.JLabel stockNameLabel;
private javax.swing.JTextField stockNameTextField;
private javax.swing.JTabbedPane tabbedPane;
private javax.swing.JLabel totalValueLabel;
// End of variables declaration
}
//StockIO.java class
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Amit Ranga
*/
public class StockIO {
private String fileName;
public StockIO() {
fileName = \"\";
}
public StockIO(String file) {
setFileName(file);
}
public ArrayList<Stock> getData() throws Exception {
BufferedReader br = null;
ArrayList<Stock> list = new ArrayList<Stock>();
try {
String line;
br = new BufferedReader(new FileReader(fileName));
while ((line = br.readLine()) != null) {
String[] s = line.split(\"\\\\s\");
if (s.length != 4) {
throw new Exception(\"Invalid input, please check your input file!!!\");
}
Stock stock = new Stock(s);
list.add(stock);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
} finally {
br.close();
}
return list;
}
public void saveData(List<Stock> stockList) {
try {
File file = new File(fileName);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
for (Stock stock: stockList) {
bw.write(stock.getCompanyName() + \" \" + stock.getNumberShares() + \" \" + stock.getCurrentPrice() + \" \" + stock.getPurchasePrice() + \"\ \");
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void setFileName(String file) {
fileName = file;
}
}
I NEED ANSWER REAL QUICK PLEASE.
Solution
public class Stock {
private String companyName;
private int numberShares;
private double purchasePrice;
private double currentPrice;
public Stock() { }
public Stock(String[] s)
{
try {
setCompanyName(s[0]);
setNumberShares(Integer.parseInt(s[1].trim()));
setPurchasePrice(Double.parseDouble(s[3].trim()));
setCurrentPrice(Double.parseDouble(s[2].trim()));
} catch (Exception e) { throw e;
}
}
public Stock(String sName, int nShares, double pPrice, double cPrice)
{
setCompanyName(sName); setNumberShares(nShares);
setPurchasePrice(pPrice); setCurrentPrice(cPrice);
}
public void setCompanyName(String cName) {
this.companyName = cName;
}
public String getCompanyName() {
return companyName;
}
public void setNumberShares(int numberShares) {
this.numberShares = numberShares;
}
public int getNumberShares() {
return numberShares;
}
public void setPurchasePrice(double purchasePrice) {
this.purchasePrice = purchasePrice;
} public double getPurchasePrice() {
return purchasePrice;
}
public void setCurrentPrice(double currentPrice)
{
this.currentPrice = currentPrice;
} public double getCurrentPrice() { return currentPrice; }
/** * * @return the profit or loss */
public double getProfitOrLoss() {
return numberShares * (currentPrice - purchasePrice); }
/** * * @return stock name */
public String toString() {
return companyName; } }
//StockGUI.java class
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
/** * * @author Amit Ranga */
public class StockGUI extends javax.swing.JFrame {
/** * Create new form Stocks4U */
public StockGUI() {
initComponents();
stockListGUI.setModel(new DefaultListModel());
}
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */
@SuppressWarnings(\"unchecked\") //
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
/**
*
* @author Amit Ranga
*/
public class StockGUI extends javax.swing.JFrame {
/**
* Create new form Stocks4U
*/
public StockGUI() {
initComponents();
stockListGUI.setModel(new DefaultListModel());
}
//StockIO.java class
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Amit Ranga
*/
public class StockIO {
private String fileName;
public StockIO() {
fileName = \"\";
}
public StockIO(String file) {
setFileName(file);
}
public ArrayList<Stock> getData() throws Exception {
BufferedReader br = null;
ArrayList<Stock> list = new ArrayList<Stock>();
try {
String line;
br = new BufferedReader(new FileReader(fileName));
while ((line = br.readLine()) != null) {
String[] s = line.split(\"\\\\s\");
if (s.length != 4) {
throw new Exception(\"Invalid input, please check your input file!!!\");
}
Stock stock = new Stock(s);
list.add(stock);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
} finally {
br.close();
}
return list;
}
public void saveData(List<Stock> stockList) {
try {
File file = new File(fileName);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
for (Stock stock: stockList) {
bw.write(stock.getCompanyName() + \" \" + stock.getNumberShares() + \" \" + stock.getCurrentPrice() + \" \" + stock.getPurchasePrice() + \"\ \");
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void setFileName(String file) {
fileName = file;
}
}













