The Stock class: Following the examples of the Circle With PrivateDataFields and TestCircleWithPrivateDataFields classes (provided on...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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... 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...
Expert Answer:
Answer rating: 100% (QA)
Stockjava Stock class begins public class Stock variable to store the symbolname previous and current stock price String symbol String name double pre... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
In Mark A. Cohen, The Costs and Benefits of Oil Spill Prevention and Enforcement, Journal of Environmental Economics and Management Vol. 13 (June 1986), an attempt was made to quantify the marginal...
-
The linear correlation coefficient is also known by another name. What is it?
-
Find an equation of the tangent line to the graph at the given point. To print an enlarged copy of the graph, go to MathGraphs.com. Kappa curve |y(x + y) = 2x y -3-2 3 2 (1, 1) -2 -3+ +11 23 X
-
Hemlock Semiconductor Operations, LLC, and SolarWorld Industries Sachsen GmbH, are both companies involved in the manufacture of components for solar power products. Prior to the lawsuit, the two...
-
The fieldwork for the June 30, 2013, audit of Tracy Brewing Company was finished August 19, 2013, and the completed financial statements, accompanied by the signed audit reports, were mailed...
-
One of the biggest impacts of ___________ is the requirement for companies and their auditors to provide reports about the effectiveness of internal controls over the financial reporting process....
-
The following is the pre-closing trial balance for Christina Rehabilitation Hospital as of September 30, 2020. Required a. Prepare a statement of operations and a statement of changes in net assets...
-
Indicate which scenarios are in equilibrium. Scenario A Scenario B m B Scenario C Scenario D Scenario FA F8 m Note: In Scenarios A & B, the block is moving. A 79.2 N 20.3 N 10.0 kg 0.600 60.1 N 30.8...
-
Isabella orders a hamburger for $4.15, french fries for $2.75, and a milkshake for $4.85. The tax is $0.95. How much change should Isabella get from $20.00?
-
A) What kind of Metro (grocery store) discounts or deals can these three loyalty programs be given? 1) Family feeders segmentation 2) Natural/healthy buyers 3) Gourmet buyers B) What would be the...
-
Liability for Antitrust Violations A group of businesses in Portland, Oregan created an association with a goal of attracting conventions to the city. The association was made up of hotels,...
-
1. What is Nielsen's expertise? 2. Providing a real-world example, describe how Nielsen might discover a consumer insight. 3. What kinds of partnerships might Nielsen need to form with other...
-
Finding the total Ratios for 2020 as well as for the Cash Flows #2 Ratios for 2020 #1 ncome Statement* 2019 2020 Balance Sheet" 2019 2020 Sources Uses Ratio Equity Corp Industry Median Sales $4,128...
-
3x 71. If =30, then x=? 2 . 8.4 b. 20 . 15 d. 6
-
Suppose the government bond described in problem 1 above is held for five years and then the savings institution acquiring the bond decides to sell it at a price of $940. Can you figure out the...
-
Parallel arrays ____________. a. Frequently have an indirect relationship b. Never have an indirect relationship c. Must be the same data type d. Must not be the same data type
-
The process of _________ a file locates it on a storage device and associates a variable name within your program with the file. a. Declaring b. Closing c. Opening d. Defining
-
A trivial Boolean expression is one that ______________. a. Is uses only two operands b. Always has the same value c. Is always true d. Is always false
-
Students form into groups of four to six members and role-play National Labor Relations Board members. Each group discusses whether Amalgamated violated the Wagner Acts prohibition of a company...
-
It has been estimated that there are around 400 million trade-union members worldwide. A third of the tradeunion members live in China, although countries such as Brazil, Russia, and Ukraine are also...
-
When employees are dissatisfied with the way they are being represented by a union, what are some tactics that employees can use to influence the union leaders to make changes in the unions goals? In...
Study smarter with the SolutionInn App