Question: This program uses the StockHolding class that we wrote in the lab for Writing Classes. Write a class PortfolioList. A PortfolioList object maintains a portfolio

This program uses the StockHolding class that we wrote in the lab for Writing Classes.

Write a class PortfolioList. A PortfolioList object maintains a portfolio of StockHolding objects by using ArrayList

PortfolioList only has a no-argument constructor

mutators: 
void add(StockHolding stock) // adds the given StockHolding to the portfolio 
void remove(String ticker) // removes the StockHolding with the given ticker from the portfolio 
accessors: 
StockHolding find(String ticker) // returns a reference to the portfolio element having the given ticker. The method should return null if there is no such element 
String toString() // returns a string containing the toString values of each element separated by newline characters ( ) Note:For manipulating the ArrayList of StockHolding objects, use only ArrayList's add, get, size and remove methods. Write a class PortfolioDriver that contains only a main method. Use the following code in PortfolioDriver 

public class PortfolioDriver {

public static void main(String[] args) {

StockHolding apple = new StockHolding("AAPL", 19, 103.97);

StockHolding ibm = new StockHolding("IBM", 10, 160.8);

StockHolding oracle = new StockHolding("ORCL", 25, 40.76);

StockHolding amazon = new StockHolding("AMZN", 22, 748.27);

PortfolioList pl1 = new PortfolioList();

PortfolioList pl2 = new PortfolioList();

pl1.add(apple);

pl1.add(ibm);

pl2.add(ibm);

pl2.add(oracle);

pl2.add(amazon);

pl2.add(apple);

System.out.println("portfolio 1: " + pl1.toString());

System.out.println("portfolio 2: " + pl2.toString());

System.out.println("Amazon: " + pl2.find("AMZN").toString());

pl2.remove("AMZN");

pl2.remove("AAPL");

pl2.remove("IBM");

pl2.remove("ORCL");

System.out.println("portfolio 2: " + pl2.toString());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!