Question: STOCK PROGRAM: public class Stock { private String Symbol; private String name; private double previousClosingPrice; private double currentPrice; Stock(String symbol, String name) { this.Symbol =

STOCK PROGRAM:

public class Stock { private String Symbol; private String name; private double previousClosingPrice; private double currentPrice; Stock(String symbol, String name) { this.Symbol = symbol; this.name = name; }

public String getSymbol() { return Symbol; }

public void setSymbol(String symbol) { Symbol = symbol; }

public String getName() { return name; }

public void setName(String name) { this.name = name; } public double getChangePercent() { return ((currentPrice - previousClosingPrice) * 100) / currentPrice; }

public void setPreviousPrice(double previous) { previousClosingPrice = previous; }

public void setCurrentPrice(double current) { currentPrice = current; }

}

STOCK TEST PROGRAM:

import java.util.Scanner;

public class StockTest { public static void main(String [] argv){ Scanner input = new Scanner(System.in); System.out.println("Please input the stock symbol: "); String symbol = input.nextLine(); System.out.println("Please input the stock name: "); String name = input.nextLine(); Stock stock = new Stock(symbol, name); // set the previous price System.out.println("Please set the previous price: "); stock.setPreviousPrice(input.nextDouble()); // set the current price System.out.println("Please set the current price: "); stock.setCurrentPrice(input.nextDouble()); System.out.println("Price Change percetage of stock is :" + stock.getChangePercent() +"% "); } }

Following the instructions in the problem statement, design and implement a Java program for programming exercise 9.2, page 360 (name it Stock.java).

Next, develop a test program in a separate file (call it TestStock.java) to create object ORCL as stated in the problem statement. Now, modify the test program to create 2 more stock objects (say MS and Google) and test all class methods on these 2 objects in logical order and display meaningful information after each method call. Document your code, and organize and space the outputs properly. Use escape characters and formatting objects when applicable.

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!