The software I use is Eclipse, please teach me how to write it on Eclipse. 1. De
ID: 3735121 • Letter: T
Question
The software I use is Eclipse, please teach me how to write it on Eclipse.
1. 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 previous 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 the specified symbol and name A method named getChangePercent) that returns the percentage changed from previousClosingPrice to currentPrice Write a test program that creates a Stock object with the symbol ORCL, the name Oracle Corporation, and the previous closing price of34.5. Set a new current price to 34.35 and display the price-change percentageExplanation / Answer
StockTest.java
public class StockTest {
public static void main(String[] args) {
Stock s = new Stock("ORCL","Oracle Corporation");
s.setPreviousClosingPrice(34.5);
s.setCurrentPrice(34.35);
System.out.println("Price change percentage: "+s.getChangePercent());
}
}
Stock.java
public class Stock
{
private String symbol,name;
private double previousClosingPrice, currentPrice;
public Stock()
{
symbol = " ";
name = " ";
previousClosingPrice = 0;
currentPrice = 0;
}
public Stock(String symbol, String name)
{
this.symbol = symbol;
this.name = name;
}
public String getSymbol()
{
return symbol;
}
public String getName()
{
return name;
}
public void setSymbol(String symbol1)
{
symbol = symbol1;
}
public void setName(String name1)
{
name = name1;
}
public double getPreviousClosingPrice()
{
return previousClosingPrice;
}
public double getChangePercent() {
return (Math.abs(previousClosingPrice-currentPrice)*100)/previousClosingPrice;
}
public double getCurrentPrice()
{
return currentPrice;
}
public void setPreviousClosingPrice(double price)
{
previousClosingPrice = price;
}
public void setCurrentPrice(double price)
{
currentPrice = price;
}
public double changePercent()
{
return (currentPrice - previousClosingPrice) / previousClosingPrice;
}
}
Output:
Price change percentage: 0.43478260869564805
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.