Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions