package lab01;


/**
 * Defines information about a specific stock holding
 * @author CS-140 Teaching Staff
 *
 */
public class Holding {
	
	/* Fields... */
	private String 	company; // Ticker symbol for this company/stock
	private int 	shares; // Number of shares of this stock held
	private double	purchasePrice; // The price at which each share of stock was bought
	
	/**
	 * Create a new holding based on parameters
	 * @param company - Stock ticker symbol for these shares
	 * @param shares - number of shares in this holding
	 * @param purchasePrice - the price paid for each share in this holding
	 */
	public Holding(String company, int shares, double purchasePrice) {
		this.company = company;
		this.shares = shares;
		this.purchasePrice = purchasePrice;
	}
	
	/**
	 * Sell specified number of shares of this holding
	 * 
	 * Will not sell more shares than are in this holding
	 * If number of sold shares are reduced, a message indicates how many are actually sold
	 * @param shares - number of shares to sell
	 * @return number of shares sold from this holding (may be less than requested)
	 */	
	public int sell(int shares) {
		if (shares>this.shares) shares=this.shares;
		// System.out.println("Selling " + shares + " shares of " + this.company);
		this.shares -= shares;
		return shares;
	}
	
	/**
	 * Figures out the net profit of selling shares at a specfic sales price
	 * 
	 * @param shares - number of shares being sold
	 * @param sellPrice - selling price
	 * @return net profit or loss from selling shares
	 */
	public double salesNet(int shares,double sellPrice) {
		if (shares>this.shares) shares=this.shares;
		return shares * ( sellPrice - this.purchasePrice) ;
	}

	/**
	 * @return the company
	 */
	public String getCompany() {
		return company;
	}

	/**
	 * @return the shares
	 */
	public int getShares() {
		return shares;
	}

	/**
	 * @return the purchasePrice
	 */
	public double getPurchasePrice() {
		return purchasePrice;
	}
}
