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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!