Question
You will implement a class named Stock. A stock has a String named symbol for the stocks symbol, and a double named price for the
You will implement a class named Stock. A stock has a String named symbol for the stocks symbol, and a double named price for the stocks current price. For example Apple stocks symbol is AAPL, price is 156.41 at this writing.
Write a constructor with 2 parameters/arguments:
public Stock(String symb, double currentPrice)
and methods:
public String getSymbol()
public double getPrice()
public void changePrice(double byPercent)
These methods return the symbol and price, and change the stocks price by a certain percentage. Note that the percentage can be + or for a price change up or down.
Stock class which tests your Stock class is given to you. You may not alter StockTester in any way.
Below.
public class StockTester
{
/**
* main() method
*/
public static void main(String[] args)
{
Stock apple = new Stock("AAPL", 156.41);
apple.changePrice(25.0); // Apple up 25.0%!
System.out.println(apple.getSymbol() + " now at: " +
apple.getPrice());
Stock oracle = new Stock("ORCL", 47.73);
oracle.changePrice(-10.0); // Oracle down 10.0!
System.out.println(oracle.getSymbol() + " now at: " +
oracle.getPrice());
}
}
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