package cse1030.Feb03;

public class Stock {
	
	private double price;
	private String symbol;
	
	/**
	 * Creates a stock with the given symbol and price.
	 * @param price Price of one share of the stock
	 * @param symbol Stock symbol
	 */
	public Stock(double price, String symbol) {
		this.price = price;
		this.symbol = symbol;
	}
	
	/**
	 * Returns the stock's symbol
	 * @return The stock's symbol
	 */
	public String getSymbol() {
		return this.symbol;
	}
	
	/**
	 * Return's the stock's price for one share.
	 * @return The stock's price for one share
	 */
	public double getPrice() {
		return this.price;
	}
	
	/**
	 * Sets the price of one share of the stock.
	 * @param price New price of one share of the stock 
	 */
	public void setPrice(double price) {
		this.price = price;
	}
	
	/**
	 * Returns a string representation of the stock. For example, if the
	 * symbol is ABC and the price for one share is $1.23, returns: 
	 * "[Stock:symbol=ABC,price=1.23]"
	 */
	public String toString() {
		return "[Stock:symbol="+this.symbol+",price="+this.price+"]";
	}

	/**
	 * Hashcode for the object.
	 * @return Hashcode for the object.
	 */
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(price);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((symbol == null) ? 0 : symbol.hashCode());
		return result;
	}

	/**
	 * Returns true if the objects are equal, false if unequal.
	 * @param obj Object to be compared to the stock
	 * @return True if the objects are equal, false if unequal
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Stock other = (Stock) obj;
		if (Double.doubleToLongBits(price) != Double
				.doubleToLongBits(other.price))
			return false;
		if (symbol == null) {
			if (other.symbol != null)
				return false;
		} else if (!symbol.equals(other.symbol))
			return false;
		return true;
	}
	
	
	
	
}
