Create a java Stock class to represent information about a stock that is bought
ID: 3567963 • Letter: C
Question
Create a java Stock class to represent information about a stock that is bought and sold on the NYSE.
It should include the stock abbreviation name price per share , and change in price per share( difference between the old stock price and the new one)
Include a parameterized contructor, setters , getters, toString, equals, copy and copr contructor methods. The equals method only compares the name. Wehn ever the stock price is changed , the change in price per share is also updates.
Be sure to include comments with the methods.
Then Create a Prefeferred Stock class that inherits from the Stock class.
It has one data member which is the dividend per share. Include a parameterized contructor , setter, getter, to string, cop, and copy constructor.
Explanation / Answer
class Stock {
private String symbol;
private String name;
private double previousClosingPrice;
private double currentPrice;
private double changeInPrice;
public Stock() {
}
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 setSymbol(String symbol) {
this.symbol = symbol;
}
public void setName(String name) {
this.name = name;
}
public void setPreviousClosingPrice(double price) {
this.previousClosingPrice = price;
}
public void setCurrentPrice(double price) {
this.currentPrice = price;
}
public void changePercent() {
changeInPrice = (currentPrice - previousClosingPrice) /previousClosingPrice;
}
}
class PreferredStock extends Stock
{
private double dividendPerShare;
public double getDividendPerShare()
{
return dividendPerShare;
}
public void setividendPerShare(double a)
{
dividendPerShare = a;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.