Reference no: EM132392375
CSE 1321: Programming and Problem Solving Lab Assignment, Kennesaw State University, USA
Exercise 1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods:
1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor.
2. A non-argument constructor method to create a default rectangle.
3. Another constructor method to create a rectangle with user-specified height and width.
4. Method getArea() that returns the area.
5. Method getPerimeter() that returns the perimeter.
6. Method getHeight() that returns the height.
7. Method getWidth() that returns the width.
Now design and implement a test program to create two rectangle objects: one with default height and width, and the second is 5 units high and 6 units wide. Next, test the class methods on each object to print the information as shown (attached).
Exercise 2: Design and implement class Stock to represent a company's stock. The class defines the following attributes (variables) and methods:
1. A class variable of type String named Symbol for the stock's symbol.
2. A class variable of type String named Name for the stock's name.
3. A class variable of type double named previousClosingPrice to store the last closing price.
4. A class variable of type double named currentPrice to store the current price.
5. A constructor method to create a stock with user-specified name and symbol.
6. Method getName() that returns the stock's name.
7. Method getSymbol() that returns the stock's symbol.
8. Method setClosingPrice() that sets the previous closing price.
9. Method setCurrentPrice() that sets the current price.
10. Method getChangePercent() that returns the percentage changed from previousClosingPrice to currentPrice.
Use the formula: (currentPrice - previousClosingPrice)/ currentPrice * 100
11. Method named toString() (Java & C#) to printout a meaningful description of a stock object when passing the object name to the print statement.
e.g.: The statement PRINT yahooStock would print the string:
Yahoo stock's closing price is $234.54.
Now design and implement a test program to create two stock objects: one for Google with symbol GOG and the second is for Microsoft with symbol MSF. Set their closing and current prices according to the information. Next, test the class methods on each object to print in the information in a similar manner to the one shown (see attached file).
Instructions: Programs must be working correctly.
Attachment:- Programming and Problem Solving Lab Assignment File.rar