-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
152 lines (111 loc) · 4.08 KB
/
Copy pathmain.java
File metadata and controls
152 lines (111 loc) · 4.08 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import java.util.Scanner;
class GroundFloor {
Scanner h = new Scanner(System.in);
float total = 0;
String[] items = {"1.Apple", "2.Banana", "3.Cherry", "4.Tomato", "5.Potato", "6.Onion"};
int[] price = {100, 40, 90, 50, 30, 60};
void fruits_Vegetables() {
char choice;
do {
System.out.println(" Ground Floor : Fruits & Vegetables ");
for (int i = 0; i < items.length; i++) {
System.out.println(items[i] + " : Rs." + price[i] + " per kg");
}
System.out.print("Choose item number: ");
int item = h.nextInt();
System.out.print("Enter quantity kg: ");
int kg = h.nextInt();
total += price[item-1] * kg;
System.out.print("Buy another item here(y/n): ");
choice = h.next().charAt(0);
} while (choice == 'y');
}
}
class FirstFloor extends GroundFloor {
String[] clothes = {"1.Shirt", "2.Pant", "3.T-Shirt", "4.Bodycon"};
int[] clothPrice = {1800, 1600, 1500, 2500};
void clothing() {
char choice;
do {
System.out.println(" First Floor : Clothing ");
for (int i = 0; i < clothes.length; i++) {
System.out.println(clothes[i] + " : Rs." + clothPrice[i]);
}
System.out.print("Choose cloth number: ");
int c = h.nextInt();
total += clothPrice[c-1];
System.out.print("Buy another cloth (y/n): ");
choice = h.next().charAt(0);
} while (choice == 'y');
}
}
class SecondFloor extends FirstFloor {
String[] groceries = {"1.Rice", "2.Oil", "3.Sugar", "4.Flour"};
int[] groceryPrice = {120, 100, 150, 70};
void grocery() {
char choice;
do {
System.out.println(" Second Floor : Groceries ");
for (int i = 0; i < groceries.length; i++) {
System.out.println(groceries[i] + " : Rs." + groceryPrice[i] + " per kg");
}
System.out.print("Choose grocery number: ");
int g = h.nextInt();
System.out.print("Enter quantity kg: ");
int kg = h.nextInt();
total += groceryPrice[g-1] * kg;
System.out.print("Buy another grocery (y/n): ");
choice = h.next().charAt(0);
} while (choice == 'y');
}
}
class Billing extends SecondFloor {
void bill() {
h.nextLine();
System.out.println(" BILL ");
System.out.print("Enter Customer Name: ");
String name = h.nextLine();
System.out.print("Enter Phone Number: ");
String phone = h.nextLine();
System.out.println("Customer Name : " + name);
System.out.println("Phone Number : " + phone);
System.out.println("Total Amount : Rs." + total);
System.out.println("Thank You Visit Again !!!");
}
}
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Billing p = new Billing();
int choice;
do {
System.out.println(" SHREE'S SUPERMARKET ");
System.out.println("1.Ground Floor (Fruits & Vegetables)");
System.out.println("2.First Floor (Clothing)");
System.out.println("3.Second Floor (Groceries)");
System.out.println("4.Billing");
System.out.println("5.Exit");
System.out.print("Enter your choice: ");
choice = s.nextInt();
switch (choice) {
case 1:
p.fruits_Vegetables();
break;
case 2:
p.clothing();
break;
case 3:
p.grocery();
break;
case 4:
p.bill();
return;
case 5:
System.out.println("Thank you for purchasing!");
break;
default:
System.out.println("Invalid choice!");
}
} while (choice != 5);
}
}