Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Stock class: Following the examples of the Circle With PrivateDataFields and TestCircleWithPrivateDataFields classes (provided on Moodle), design a class named Stock that contains:


image  

image 

The Stock class: Following the examples of the Circle With PrivateDataFields and TestCircleWithPrivateDataFields classes (provided on Moodle), design a class named Stock that contains: A String data field named symbol, for the stock's symbol. A String data field named name, for the stock's name. A double data field named previous Closing Price that stores the stock price for the previous day. A double data field named currentPrice that stores the stock price for the current time. "Getter" and "Setter" methods for each of the data fields (as needed): getSymbol(), setSymbol(), getName(), setName(), getPrevious Closing Price(), setPrevious Closing Price(), getCurrentPrice(), setCurrentPrice(). Note: Depending on the details of your design, you may or may not need all of these "getter" and "setter" methods. Implement those that you find necessary to make your solution work correctly. A constructor that creates a stock with a specified symbol and name. A method named getChange Percent() that returns the percentage changed from previous Closing Price to currentPrice. Write a test program that prompts the user for a stock symbol. If the user enters "q", then the program must exit. If the user enters anything other than "q", then the program must assume that the input represents a stock symbol. After a stock symbol is input, the program must prompt the user for the company name associated with the stock symbol, and also the company's previous closing price and current price. The program must create an instance of the Stock class, and utilize the appropriate set methods to set the object's internal field values. After the object is created and its member variables are set, the program must call the getChangePercent() method to determine how much the stock price has changed. When this processing is finished for one stock, the main loop must ask the user for another stock symbol, and repeat the process. The program exits when the user enters the string "q" in place of a stock symbol. Your program must have two classes: a public class named Lab9a, and another (non-public) class named Stock. The Lab9a class contains a main () method, which creates an object of the Stock class. HINT: You will need to create a Scanner object to input the various data values from the console. You may find difficulties if your program uses both Scanner.nextLine() and Scanner.nextDouble () methods: on repeated passes through the main loop, the program appears to skip over the statement that inputs the stock symbol. One way to avoid such problems is to use Scanner.nextLine() for all inputs, and then convert the input strings to double values by calling Double.parseDouble() where necessary. Sample Output In the sample output shown, text that the user types is shown in BOLD font. When the program actually runs, all text is shown in the same font. Enter stock Symbol (or 'q' to exit): ORCL Enter company name: Oracle Corporation Enter previous closing price: 88.90 Enter current price: 97.50 SYMBOL ORCL, NAME=Oracle Corporation, Previous Price=88.90, Current Price=97.50, Percent Change= +9.67 % Enter stock Symbol (or 'q' to exit): IBM Enter company name: International Business Machines Enter previous closing price: 134.22 Enter current price: 111 SYMBOL IBM, NAME=International Business Machines, Previous Price=134.22, Current Price=111.00, Percent Change--17.30 % Enter stock Symbol (or 'q' to exit): q Exiting program...

Step by Step Solution

3.37 Rating (147 Votes )

There are 3 Steps involved in it

Step: 1

Stockjava Stock class begins public class Stock variable to store the symbolname previous and current stock price String symbol String name double pre... 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

Programming Logic & Design Comprehensive

Authors: Joyce Farrell

9th edition

978-1337102070

More Books

Students also viewed these Programming questions