Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in java Design a class named Stock that contains: A string data field named symb

ID: 3904265 • Letter: I

Question

in java

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 previousClosingPrice that stores the stock price for the previous day.

A double data field named currentPrice that stores the stock price for the current time.

A constructor that creates a stock with specified symbol and name.

The accessor methods for all data fields.

The mutator methods for previousClosingPrice and currentPrice.

A method named changePercent() that returns the percentage changed from previousClosingPrice to currentPrice.

Draw the UML diagram for the class. Implement the class. Write a test program that creates a Stock object with the stock symbol GOOG, the name Google Inc., and the previous closing price of 100. Set a new current price to 90 and display the price-change percentage.

Explanation / Answer

public class Stock { private String symbol; private String name; private double previousClosingPrice; private double currentPrice; public Stock(String symbol, String name) { this.symbol = symbol; this.name = name; } public String getSymbol() { return symbol; } public String getName() { return name; } public double getPreviousClosingPrice() { return previousClosingPrice; } public double getCurrentPrice() { return currentPrice; } public void setPreviousClosingPrice(double previousClosingPrice) { this.previousClosingPrice = previousClosingPrice; } public void setCurrentPrice(double currentPrice) { this.currentPrice = currentPrice; } public double changePercent() { return ((currentPrice - previousClosingPrice) / previousClosingPrice) * 100; } }