Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write the definition of a class that has the following properties: a. The name of the class is Stock. b. The class Stock has four
Write the definition of a class that has the following properties: a. The name of the class is Stock. b. The class Stock has four instance variables: name of type String, previousPrice and closingPrice of type double, and numberOfShares of type int. c. The class Stock has the following methods: toString-to return the data stored in the data members with the appropriate titles as a string setName-method to set the name setPreviousPrice-method to set the previous price of a stock. (This is the closing price of the previous day.) setClosingPrice-method to set the closing price of a stock setNumberOfShare-method to set the number of shares owned by the stock getName-value-returning method to return the name getPreviousPrice-value-returning method to return the previous price of the stock getClosingPrice-value-returning method to return the closing price of the stock getNumberOfShare-value-returning method to return the number of shares owned by the stock 544 | Chapter 8: User-Defined Classes and ADTs percentGain-value-returning method to return the change in the stock value from the previous closing price and today's closing price as a percentage share Values-value-returning method to calculate and return the total values of the shares owned default constructor-the default value of name is the empty string ""; the default values of previousPrice, closingPrice, and numberOfShares are 0. constructor with parameters-sets the values of the instance variables name, previousPrice, closingPrice, and numberOfShares to the values specified by the user d. Write the definitions of the methods and constructors of the class Stock as described in part c
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started