Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

What clues might indicate an unreliable franchisor?

Answered: 1 week ago

Question

Describe alternative paid time off policies.

Answered: 1 week ago

Question

Describe customized benefit plans.

Answered: 1 week ago