1
+ package Final ;
2
+ import java .util .Scanner ;
3
+ class ShortcakeCafe extends CakeFactory {
4
+
5
+ public static void main (String [] args ) {
6
+ System .out .println ("-----------Welcome to SHORT-CAKE CAFE-----------" );
7
+ CakeFactory cf =new CakeFactory ();
8
+ Cake c ;
9
+ StringBuilder cake_name = new StringBuilder ();
10
+ Scanner s =new Scanner (System .in );
11
+ System .out .print ("Enter the number of cakes: " );
12
+ int number_of_cakes =s .nextInt ();
13
+ int price =0 ;
14
+ for (int i =0 ;i <number_of_cakes ;i ++){
15
+ System .out .println ("Do you want an" );
16
+ System .out .println ("1)Eggless cake, or" );
17
+ System .out .println ("2)Egg cake" );
18
+ System .out .println ("Enter your choice: " );
19
+ int base_choice =s .nextInt ();
20
+ final String base ;
21
+ if (base_choice ==1 ){
22
+ base ="eggless" ;
23
+ c =cf .createCake (base );
24
+ c .templateMethod (number_of_cakes );
25
+ price +=c .cakePrice ();
26
+ // cake_name.append(c.cakeName());
27
+ }
28
+ else if (base_choice ==2 ){
29
+ base ="" ;
30
+ c =cf .createCake (base );
31
+ c .templateMethod (number_of_cakes );
32
+ price +=c .cakePrice ();
33
+ // cake_name.append(c.cakeName());
34
+ }
35
+ System .out .println ("Which flavour of cake would you like to have?" );
36
+ System .out .println ("1)Chocolate cake, or" );
37
+ System .out .println ("2)Mango cake, or" );
38
+ System .out .println ("3)Strawberry cake" );
39
+ int flavour_num =s .nextInt ();
40
+ final String flavour ;
41
+ if (flavour_num ==1 ){
42
+ flavour ="chocolate" ;
43
+ c =cf .createCake (flavour );
44
+ c .templateMethod (number_of_cakes );
45
+ price +=c .cakePrice ();
46
+ // cake_name.append(c.cakeName());
47
+ }
48
+ else if (flavour_num ==2 ){
49
+ flavour ="mango" ;
50
+ c =cf .createCake (flavour );
51
+ c .templateMethod (number_of_cakes );
52
+ price +=c .cakePrice ();
53
+ // cake_name.append(c.cakeName());
54
+ }
55
+ else if (flavour_num ==3 ){
56
+ flavour ="strawberry" ;
57
+ c =cf .createCake (flavour );
58
+ c .templateMethod (number_of_cakes );
59
+ price +=c .cakePrice ();
60
+ // cake_name.append(c.cakeName());
61
+ }
62
+ System .out .println ("Which topping would you like to have on your cake?" );
63
+ System .out .println ("1)Nuts, or" );
64
+ System .out .println ("2)Oreo, or" );
65
+ int topping_num =s .nextInt ();
66
+ final String topping ;
67
+ if (topping_num ==1 ){
68
+ topping ="nuts" ;
69
+ c =cf .createCake (topping );
70
+ c .templateMethod (number_of_cakes );
71
+ price +=c .cakePrice ();
72
+ cake_name .append (c .cakeName ());
73
+ }
74
+ else if (topping_num ==2 ){
75
+ topping ="oreo" ;
76
+ c =cf .createCake (topping );
77
+ c .templateMethod (number_of_cakes );
78
+ price +=c .cakePrice ();
79
+ cake_name .append (c .cakeName ());
80
+ }
81
+ cake_name .append (" and a " );
82
+ }
83
+ System .out .println ("Your order details: " );
84
+ System .out .println ("Number of cake(s): " +number_of_cakes );
85
+ System .out .println ("Cake: " +cake_name );
86
+ System .out .println ("Total Amount: Rs " +price );
87
+ System .out .print ("Bon Appétit (:" );
88
+ }
89
+ }
0 commit comments