/**
 *
 */
package lab01;
import java.time.LocalTime;
import java.util.Scanner;

/**
 * Keep track of the price of a single share of stock
 *
 * @author CS-140 Teaching Staff
 *
 */
public class Quote {

	/* Fields... */
	private LocalTime timeStamp; // Time when the quote was generated
	private String company; // Name of the stock (Ticker Tab Symbol)
	private double price; // Price (in dollars and cents) of one share of the stock

	/**
	 * Create a quote with the current date/time based on parameters
	 *
	 * @param company - Ticker take symbol for this quote
	 * @param price - Price associated with one share of stock for this quote
	 */
	public Quote(String company, double price) {
		this.company = company;
		this.price = price;
		this.timeStamp = java.time.LocalTime.now();
	}

	/**
	 * Create a quote with the current date/time based on a string
	 *
	 * @param qspec - string that contains:<ol>
	 * 	<li>The stock name (company name)
	 * 	<li>The current stock price for a single share in dollars and cents</ol>
	 * @throws IllegalArgumentException if the input string is not a valid quotation
	 */
	public Quote(String qspec) {
		Scanner in=new Scanner(qspec);
		if(in.hasNext()) {
			this.company=in.next();
			if (in.hasNextDouble()) {
				this.price=in.nextDouble();
			} else {
				in.close();
				throw new IllegalArgumentException("illegal quote specification");
			}
		} else {
			in.close();
			throw new IllegalArgumentException("illegal quote specification");
		}
		in.close();
		this.timeStamp = java.time.LocalTime.now();
	}
	/**
	 * @return the price
	 */
	public double getPrice() {
		return price;
	}
	/**
	 * @return the company
	 */
	public String getCompany() {
		return company;
	}

	/**
	 * @param compare - Name of stock to compare to
	 * @return true if this quote is for the compare ticker tape symbol
	 * @see java.lang.String#equals(java.lang.Object)
	 */
	public boolean companyEquals(String compare) {
		return company.equals(compare);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Quote [timeStamp=" + timeStamp + ", company=" + company + ", price=" + price + "]";
	}

	/**
	 * Checks to see if this quote is newer than the argument
	 * @param comp - quote to compare to
	 * @return true if this is newer, false if comp is newer
	 */
	public boolean isNewer(Quote comp) {
		return this.timeStamp.isAfter(comp.timeStamp);
	}

}
