pizza.java

来自「java编的销售系统」· Java 代码 · 共 97 行

JAVA
97
字号

public class Pizza
{
	private PizzaType pizzaType;
	private String baseType;
	private int size;
	private Topping toppings;
	private BakeSpeed bakeSpeed;
	private int quantity;
	
	public Pizza(PizzaType aPizzaType,String aBaseType, int aSize, Topping aToppings, 
		BakeSpeed aBakeSpeed, int aQuantity)
	{
		pizzaType=aPizzaType;
		baseType = aBaseType;
		size = aSize;
		toppings = aToppings;
		bakeSpeed = aBakeSpeed;
	    quantity = aQuantity;
	}
	
	//get base type 
	public String getBaseTypeName()
	{
		return baseType;
	}
	
	//set and get size
	public void setSize(int aSize)
	{
		size = aSize;
	}
	
	public int getSize()
	{
		return size;
	}
	
	//add toppings
	public void setTopping(Topping aToppings)
	{
		toppings = aToppings;
	}
	
	public String getToppingName()
	{
		return toppings.getToppName();
	}
	
	public int getToppingPrice()
	{
		return toppings.getToppPrice();
	}
	
	//add Bake Speed and get bake speed name and bake speed price
	public void setBakeSpeed(BakeSpeed aBakeSpeed)
	{
		bakeSpeed = aBakeSpeed;
	}
	
	public String getBakeSpeedName()
	{
		return bakeSpeed.getClass().getName();
	}
	
	public int getBakeSpeedPrice()
	{
		return bakeSpeed.getBakePrice();
	}
	
	//get quantiyty
	public int getQuantity()
	{
		return quantity;
	}
	
	public PizzaType getPizzaType()
	{
		return pizzaType;
	}
	
	public int getPrice()
	{
		return (this.getBakeSpeedPrice()+this.getToppingPrice()+this.getPizzaType().getPrice())*quantity;
	}
	
	public String toString()
	{
		return pizzaType.getTypeName()+ "  ,  " 
			+getBaseTypeName() + " , "
			+getSize() + "  ,  "
			+getToppingName() + " , "
			+getBakeSpeedName() + " , "
			+getQuantity() + "\n";
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?