-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPizza.java
More file actions
41 lines (38 loc) · 1.3 KB
/
Pizza.java
File metadata and controls
41 lines (38 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package lesson3;
public class Pizza {
private PizzaSize pizzaSize;
private PizzaType pizzaType;
private int quantity;
private double price;
public Pizza(PizzaSize pizzaSize, PizzaType pizzaType, int quantity){
if(quantity<=0){
throw new IllegalArgumentException("Quantity must be greater than Zero");
}
this.pizzaSize=pizzaSize;
this.pizzaType=pizzaType;
this.quantity=quantity;
calculatePrice();
}
private void calculatePrice(){
double sizePrice=switch (pizzaSize){
case SMALL->8;
case MEDIUM ->10;
case LARGE -> 12;
};
double typePrice=switch(pizzaType){
case VEGGIE -> 1;
case CHEEZE -> 1.5;
case BBQ_CHICKEN -> 2;
case PEPPERONI -> 2;
};
this.price=(sizePrice+typePrice)*quantity;
}
public String printOrderSummary(){
double tax=price*0.3;
double totalPrice=price+tax;
return String.format("Pizza Order:%n" +
"Size: %s%n" + "Type: %s%n" +
"Qty: %d%n" + "Price: $%.2f%n" +
"Tax: $%.2f%n" + "Total Price: $%.2f%n", pizzaSize, pizzaType, quantity, price, tax, totalPrice);
}
}