Product Class

/**
 *A product has a name and a price.
 */
public class Product
{
	String name;
	double price;
	
	/**
	 *Creates a product with a specified name and price of 0.
	 *@param newName Specifes name of product.
	 */
	public Product(String newName)
	{
		name=newName;
		price=0;
	}
	
	/**
	 *Creates a product with a specified name and price.
	 *@param newName Specifies name of product.
	 *@param newPrice Specifies price of product.
	 */
	public Product(String newName, double newPrice)
	{
		name=newName;
		price=newPrice;
	}
	
	
	/**
	 *Gets the name.
	 *@return newName Returns name.
	 */
	 public String getName()
	 {
	 	return name;
	 }
	 
	 /**
	  *Gets the price.
	  *@returns Returns price.
	  */
	 public double getPrice()
	 {
	 	return price;
	 }
	 
	 /**
	  *Changes the price.
	  *@param newPrice Specifies price to change price to.
	  */
	 public void setPrice(double newPrice)
	 {
	 	price=newPrice;
	 }
	 
	 /**
	  *Reduces price by a given percentage.
	  *@param percent Specifies percentage to reduce price by.
	  */
	 public void setSalePrice(int percent)
	 {
	 	price-=price*(percent/100.0);
	 }
	 
}

/* OUTPUT FROM DEMO
Regular Prices
Dove 1.29
Irish Spring 1.49

Sale Prices:
Dove 1.0965
Irish Spring 1.2665
Press any key to continue...
*/



Home
Site hosted by Angelfire.com: Build your free website today!