-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmritaFoodOrderingSystem.java
More file actions
228 lines (196 loc) · 8.58 KB
/
Copy pathAmritaFoodOrderingSystem.java
File metadata and controls
228 lines (196 loc) · 8.58 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
public class AmritaFoodOrderingSystem {
static ArrayList<MenuItem> menu = new ArrayList<>();
static double dailySales = 0.0;
static int currentImageIndex = 0; // Initialize image index
static String[] images = {
"assets/welcome1.jpg",
"assets/welcome2.png",
"assets/welcome3.png",
"assets/welcome4.jpg"
};
public static void main(String[] args) {
initializeMenu();
JFrame frame = new JFrame("Amrita Food Ordering System");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
frame.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
// Header and Image
JLabel welcomeLabel = new JLabel("Welcome to Amrita Food Ordering System", SwingConstants.CENTER);
welcomeLabel.setFont(new Font("Arial", Font.BOLD, 16));
JLabel imageLabel = new JLabel(new ImageIcon(images[currentImageIndex])); // Set initial image
// Start a timer to update images every 10 seconds
new javax.swing.Timer(10000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
currentImageIndex = (currentImageIndex + 1) % images.length; // Cycle through images
imageLabel.setIcon(new ImageIcon(images[currentImageIndex])); // Update the image
}
}).start();
// Customer Name Input
JLabel nameLabel = new JLabel("Customer Name:");
JTextField nameField = new JTextField(15);
// Menu and Quantity Select
JLabel menuLabel = new JLabel("Select Items and Quantity:");
JPanel menuPanel = new JPanel(new GridLayout(menu.size(), 3, 10, 10));
ArrayList<JSpinner> quantitySpinners = new ArrayList<>();
for (MenuItem item : menu) {
menuPanel.add(new JLabel(item.name + " - Rs. " + item.price));
JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, 10, 1));
quantitySpinners.add(spinner);
menuPanel.add(spinner);
}
// Buttons
JButton placeOrderButton = new JButton("Place Order");
JButton adminButton = new JButton("Admin Login");
// Layout the components
gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; frame.add(welcomeLabel, gbc);
gbc.gridy = 1; frame.add(imageLabel, gbc);
gbc.gridy = 2; frame.add(nameLabel, gbc);
gbc.gridy = 3; frame.add(nameField, gbc);
gbc.gridy = 4; frame.add(menuLabel, gbc);
gbc.gridy = 5; frame.add(new JScrollPane(menuPanel), gbc);
gbc.gridy = 6; frame.add(placeOrderButton, gbc);
gbc.gridy = 7; frame.add(adminButton, gbc);
frame.setVisible(true);
// Place Order Action
placeOrderButton.addActionListener(e -> {
String customerName = nameField.getText().trim();
if (customerName.isEmpty()) {
JOptionPane.showMessageDialog(frame, "Enter customer name!");
return;
}
Order order = new Order(customerName);
for (int i = 0; i < menu.size(); i++) {
int quantity = (int) quantitySpinners.get(i).getValue();
if (quantity > 0) {
order.addItem(menu.get(i).name, menu.get(i).price, quantity);
}
}
if (order.orderedItems.isEmpty()) {
JOptionPane.showMessageDialog(frame, "No items selected!");
return;
}
dailySales += order.getFinalTotal();
order.saveBill();
// Display order details with discount
JOptionPane.showMessageDialog(frame,
"Order placed successfully!\n" +
"Subtotal: Rs. " + order.total + "\n" +
"Discount: " + (order.calculateDiscount() * 100) + "%\n" +
"Final Total: Rs. " + order.getFinalTotal()
);
});
// Admin Login Action
adminButton.addActionListener(e -> {
String password = JOptionPane.showInputDialog(frame, "Enter Admin Password:");
if ("admin123".equals(password)) {
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String filePath = "revenue/revenue_" + date + ".txt";
double savedRevenue = 0.0;
// Calculate saved revenue from the file
File revenueFile = new File(filePath);
if (revenueFile.exists()) {
try (BufferedReader reader = new BufferedReader(new FileReader(revenueFile))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.startsWith("Total Revenue for")) {
String[] parts = line.split(": Rs. ");
if (parts.length > 1) {
savedRevenue += Double.parseDouble(parts[1].trim());
}
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
// Write updated revenue to the file
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true))) {
writer.write("Total Revenue for " + date + ": Rs. " + dailySales + "\n");
} catch (IOException ex) {
ex.printStackTrace();
}
// Calculate net total revenue (saved + session revenue)
double netRevenue = savedRevenue + dailySales;
// Display revenue details
JOptionPane.showMessageDialog(frame,
"Today's Total Revenue: Rs. " + dailySales + "\n" +
"Cumulative Net Revenue: Rs. " + netRevenue
);
} else {
JOptionPane.showMessageDialog(frame, "Invalid Password!");
}
});
}
private static void initializeMenu() {
menu.add(new MenuItem("Spring Rolls", 150));
menu.add(new MenuItem("Samosa", 50));
menu.add(new MenuItem("Pizza", 300));
menu.add(new MenuItem("Burger", 200));
menu.add(new MenuItem("Pasta", 250));
menu.add(new MenuItem("Coke", 50));
menu.add(new MenuItem("Ice Cream", 100));
menu.add(new MenuItem("Brownie", 120));
}
}
// Class for Menu Item
class MenuItem {
String name;
double price;
MenuItem(String name, double price) {
this.name = name;
this.price = price;
}
}
// Class for Customer Order
class Order {
String customerName;
ArrayList<String> orderedItems;
double total;
public Order(String customerName) {
this.customerName = customerName;
this.orderedItems = new ArrayList<>();
this.total = 0.0;
}
void addItem(String itemName, double price, int quantity) {
orderedItems.add(itemName + " x" + quantity + " - Rs. " + (price * quantity));
total += (price * quantity);
}
double calculateDiscount() {
if (total > 1500) return 0.20; // 20% discount
if (total > 1000) return 0.10; // 10% discount
if (total > 500) return 0.05; // 5% discount
return 0.0;
}
double getFinalTotal() {
return total * (1 - calculateDiscount());
}
void saveBill() {
try {
String folderPath = "C:\\Users\\Abinash DAS\\Desktop\\New folder\\revenue";
File folder = new File(folderPath);
if (!folder.exists()) folder.mkdirs();
String date = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
String filename = folderPath + "\\" + customerName + "_bill_" + date + ".txt";
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
writer.write("Bill for: " + customerName + "\n");
for (String item : orderedItems) {
writer.write(item + "\n");
}
writer.write("\nSubtotal: Rs. " + total);
writer.write("\nDiscount: " + (calculateDiscount() * 100) + "%");
writer.write("\nTotal: Rs. " + getFinalTotal());
writer.write("\n\nThank you for ordering!");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}