-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPizzaPriceGenrator.java
More file actions
105 lines (85 loc) · 2.7 KB
/
PizzaPriceGenrator.java
File metadata and controls
105 lines (85 loc) · 2.7 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
public class PizzaPriceGenrator {
static class pizza {
private int price;
private boolean veg;
private int extraCheese = 100;
private int extraToppings = 150;
private int takeAway = 20;
private int basePizzaPrice;
boolean isExtracheeseAdded=false;
boolean isExtraTooping=false;
boolean isOptedFortakeaway=false;
// private boolean check;
public pizza(boolean veg) {
// this.check=false;
this.veg = veg;
if (this.veg) {
this.price = 300;
} else {
this.price = 400;
}
this.basePizzaPrice=this.price;
}
public void addextraCheese() { // check=true;
this.isExtracheeseAdded=true;
// System.out.println("Extra Cheese Added");
this.price += this.extraCheese;
}
public void addextraToppings() { // check=true;
this.isExtraTooping=true;
// System.out.println("Extra Toppings Added");
this.price += this.extraToppings;
}
public void addtakeaway() {
this.isOptedFortakeaway=true;
// System.out.println("Take away opted");
this.price = price + takeAway;
}
public void getBill() {
String bill="";
System.out.println("Pizza :"+basePizzaPrice);
if(isExtraTooping)
{
bill+="Extra Topping Added :" +extraToppings+"\n";
}
if(isOptedFortakeaway)
{
bill+="takeaway charge :" +takeAway+"\n";
}
if(isExtracheeseAdded)
{
bill+="Extra Cheese:" +extraCheese+"\n";
}
bill+="Bill "+this.price +'\n';
System.out.println(bill);
}
}
static class DeluxPizza extends pizza
{
public DeluxPizza(boolean veg)
{
super(veg);
// bydefult rehte he
super.addextraCheese();
super.addextraToppings();
}
//in this clss we ovverride this function as a do nothing function
// sp that is user intemtionally want to add pizza pricw then he cannt
@Override
public void addextraCheese(){}
@Override
public void addextraToppings(){}
}
public static void main(String[] args) {
// pizza p1 = new pizza(true);
// p1.addextraCheese();
// p1.addextraToppings();
// p1.addtakeaway();
// p1.getBill();
DeluxPizza dp = new DeluxPizza(true);
dp.addextraCheese();
dp.addextraToppings(); // not work
dp.addtakeaway();
dp.getBill();
}
}