Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that simulates adding stock name and price in the stock market. The class name is StockMarket. Assume that your stock market has

Write a program that simulates adding stock name and price in the stock market. The class name is StockMarket. Assume that your stock market has only 3 stocks. Your class needs to have the following methods:
StockMarket()// intitlaize your 3 stocks with the price 0
StockMarket(double price)// initialize your 3 stocks with the given price value
setStockName(int index, String stockName)// set the stock number (index) name into stockName
setStockPrice(int index, double newPrice) // set the stock number (index) price into newPrice
getStockName(int index) // get the name for stock number (index)
getStockPrice(int index) // get the price for stock number (index)
Test your class in the main by defining one object of StockMarket and then set a name for stock in index 1 to be facebook and the price to be 25. Then use the object to printout the values for that stock.
2) Add to the previous class StockMarket 3 new methods for printing the stock name and price as follows:
display()// will print the 3 stocks names and prices
display(int index) //will print the stock name and price for the given index
display(String stockName) //will print the price for the given stockName
Test your class in the main by defining one object of stockMarket and then set a name for stock in index 2 to be Google and the price to be 35. Then use the object to test your two new methods.

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions