// A Stock object represents purchases of shares of a stock
public class Stock1 {
   private String symbol;      // stock symbol, e.g. "GOOG"
   private double totalCost;   // price paid for all shares
	private int sharesOwned;    // number of shares owned

	// Create a new stock given a symbol
	// Initially, no shares purchased
   public Stock1(String s) {
		this.symbol = s;
		this.totalCost = 0;
		this.sharesOwned = 0;
   }

	// returns the total profit or loss earned on stock
	public double getProfit(double currentPrice) {
		if(currentPrice < 0.0) {
			throw new IllegalArgumentException("Current stock price must be positive");
		}
		return currentPrice * sharesOwned - totalCost;
	}
	
	// records purchase of given shares at given price
	public void purchase(int shares, double pricePerShare) {
		if(shares < 0 || pricePerShare < 0.0) {
			throw new IllegalArgumentException();
		}
		this.sharesOwned += shares;
		this.totalCost += shares * pricePerShare;
	}

	// returns shares owned, total cost and current pric		
	public String toString() {
		return this.symbol + ": " + this.sharesOwned + " owned purchased for an average of $" + this.totalCost / this.sharesOwned;
	}
	
	// Getter for the three fields so we can view but not modify them
	public int getSharesOwned() {
		return this.sharesOwned;
	}
	
	public String getSymbol() {
		return this.symbol;
	}
	
	public double getTotalCost() {
		return this.totalCost;
	}
}
