// This class represents a piece of stock that a person might own public class Stock { private String symbol, name; // symbol is the Stock Market abbreviation, name is the name of the company private double previousClosingPrice, currentPrice; // the worth of 1 share of stock from the last market close and today's market close public Stock(String s, String n) // constructor which initializes Stock's worth to 0 { symbol=s; name=n; currentPrice=previousClosingPrice=0.0; } public void newCurrentPrice(double newValue) // If legal new value, move current Stock's worth to previousClosingPrice, and assign new worth to currentPrice { if(newValue>=0) { previousClosingPrice=currentPrice; currentPrice=newValue; } else System.out.println("Erroneous value " + newValue); } public void setPreviousClosingPrice(double value) // if new value is legal, reset previousClosingPrice to new { if(value>=0) previousClosingPrice=value; else System.out.println("Erroneous value " + value); } public void setCurrentPrice(double value) // if new value is legal, reset currentPrice to new { if(value>=0) currentPrice=value; else System.out.println("Erroneous value " + value); } public double getChangePercent() // compute the percentage change from previousClosingPrice to currentPrice and return as a double { return (previousClosingPrice - currentPrice)/currentPrice; } }