Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming Goals In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to

Java Programming

Goals

In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to

Write classes that use arrays and ArrayLists of objects as instance variables

Write methods that process arrays and ArrayLists of objects

Write getter and setter methods for instance variables

Write methods using object parameters and primitive types

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 of StockHolding objects. A PortfolioList

keeps an ArrayList

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. The main method should create two PortfolioList objects. It should add two StockHolding objects to one portfolio, and 4 to the other. It should print both portfolios. It should find and print the toString value of a stock in one portfolio. It should delete all of the StockHolding objects from the portfolio with 4 objects, and print the portfolio. 

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_2

Step: 3

blur-text-image_3

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 Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago

Question

=+When and under what circumstances are contracts renegotiated?

Answered: 1 week ago

Question

=+Are the contracts enforceable?

Answered: 1 week ago