// Arup Guha
// 11/2/2009
// Solution to AP CS A Exam 2 Question: Stock

public class Stock {

    private String name;
  	private double price;
  	private int numshares;

  	// Creates a stock object with the name n, price p and shares
  	// number of shares.
  	public Stock(String n, double p, int shares) {
      	name = n; // 3 pts
      	price = p; // 3 pts
      	numshares = shares; // 3 pts
  	}

  	// Changes the price of this stock by change, which may be
  	// positive or negative.
  	public void deltaPrice(double change) {
      	price = price + change; // 8 pts
  	}

  	// Splits a stock by doubling its number of shares and
  	// dividing its price by two.
  	public void split() { 
      	price = price/2;  // 5 pts
      	numshares = numshares*2; // 5 pts
  	}

  	// Creates and returns a new Stock object with name n that
  	// has 10% of the price of this Stock and the same number of
  	// shares. This stock’s price is subsequently reduced by 10%.
  	public Stock sisterFirm(String n) { 
      	Stock sister = new Stock(n, .1*price, numshares); // 10 pts
      	price = .9*price; // 4 pts
      	return sister; // 3 pts
  	}

  	// Returns a String representation of this Stock which 
  	// includes just the name and price.
  	public String toString() { 
        return name+" "+price; // 8 pts
  	}

}
