import java.util.ArrayList;
public class PissaApp {
enum PissaSize{
big,medium,small
}
abstract class Topping {
String name = null;
int price = 0;
private int num = 0;
public void setNum(int number){
this.num = number;
}
public int getNum(){
return this.num;
}
public int getPrice(){
return this.price;
}
}
class DoubleCheese extends Topping{
DoubleCheese(){
this.name = "DoubleCheese";
this.price = 2;
this.num = 1;
}
}
class Cheese extends Topping{
Cheese(){
this.name = name;
this.price = 1;
}
}
class Tomato extends Topping{
Tomato(){
this.name = name;
this.price = 1;
}
}
class Sausage extends Topping{
Sausage(){
this.name = name;
this.price = 2;
}
}
class Mushroom extends Topping{
Mushroom(String name, int price){
this.name = name;
this.price = 2;
}
}
class Pissa{
private String custorName;
private PissaSize pissaSize;
private int toppingNum;
private ArrayList<Topping> allToppings;
private int price;
public Pissa(String customer,PissaSize size){
this.custorName = customer;
this.pissaSize = size;
this.toppingNum = 0;
this.allToppings = new ArrayList<Topping>();
switch(size){
case PissaSize.small:
price = 5;
case PissaSize.medium:
price = 10;
case PissaSize.big:
price = 15;
defult:
break;
}
}
public int calculatePrice(){
for(Topping top: this.allToppings){
price += top.price * top.num;
}
return price;
}
public void addToppings(Topping topping, int num){
topping.setNum(num);
this.toppingNum++;
this.allToppings.add(topping);
}
}
}
No comments:
Post a Comment