Question
FILES PROVIDED: FinalProject_MainClass.java portfolioStocks.txt TASKS: 1. Name your Project: FinalProject. 2. Create a package within your Project called BrokeragePkg. 3. You should have 4 classes
FILES PROVIDED:
FinalProject_MainClass.java
portfolioStocks.txt
TASKS:
1. Name your Project: "FinalProject".
2. Create a package within your Project called "BrokeragePkg".
3. You should have 4 classes in the BrokeragePkg: Brokerage, Portfolio, Stock, and FinalProject_MainClass.
4. The Brokerage class should contain a construtor and a private String brokerageName attribute with appropriate getter/setter methods, along with a public Portfolio ArrayList attribute.
5. The Portfolio and Stock classes should be very much as you have them for your earlier programs, but change the doubles to ints for previousClosingPrice and currentPrice, and their methods, as well. The Portfolio class should have a private int portfolioID attribute.
6. Inside the FinalProject_MainClass I've given you, change the direct-access calls to data members so that they use the get() and set() methods of your classes.
7. Add to the inner for-loop output the change percentage functionality you did for your Stock program (the last output line is println() you'll notice.. the others are simply print(), keep that in mind for proper formatting).
portfolioStocks.txt =
445 GTC GwinTech 60 65 445 ITT ITTTech 22 23 445 GTH GATech 44 49 988 XTC EXTREM 67 71 988 HVP HALVP 83 87 988 LAC LACTOSE 99 101 988 ZLK ZEBRALINES 77 87 988 VTA VITAPILL 91 99 617 BKC BACKPCK 11 14 617 XXV EXCITEV 66 81
FinalProject_MainClass.java(
package BrokeragePkg; import java.io.*; import javax.swing.*; import java.util.*; public class FinalProject_MainClass { public static void main(String[] args) { Brokerage brk = new Brokerage("Paine Webber"); JFileChooser fileOpenDlg = new JFileChooser(); int status = -1; do { status = fileOpenDlg.showOpenDialog(null); if (status == JFileChooser.CANCEL_OPTION) { JOptionPane.showMessageDialog(null, "You've chosen to cancel the program. Exiting."); System.exit(0); } } while (status != JFileChooser.APPROVE_OPTION); int tmpPortID = -1; int tmpInt = -1; int numPortfolios = -1; try { File selectedFile = fileOpenDlg.getSelectedFile(); Scanner myScan = new Scanner(selectedFile); while (myScan.hasNext()) { tmpInt = myScan.nextInt(); if (tmpPortID != tmpInt) { Portfolio p = new Portfolio(); p.portfolioID = tmpInt; brk.portfolioList.add(p); tmpPortID = tmpInt; numPortfolios++; } Stock s = new Stock(); s.symbol = myScan.next(); s.name = myScan.next(); s.prevPrice = myScan.nextInt(); s.currPrice = myScan.nextInt(); brk.portfolioList.get(numPortfolios).stockList.add(s); } System.out.println("Brokerage: " + brk.brokerageName); for (Portfolio port: brk.portfolioList) { System.out.println(" Portfolio ID: " + port.portfolioID + " "); for (int i = 0; i < port.stockList.size(); i++) { System.out.print(port.stockList.get(i).symbol + " "); System.out.print(port.stockList.get(i).name + " "); System.out.print(port.stockList.get(i).prevPrice + " "); System.out.println(port.stockList.get(i).currPrice + " "); } } } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + " Exiting."); } catch (InputMismatchException ex) { JOptionPane.showMessageDialog(null, "Wrong file type selected." + " Exiting."); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started