-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderingSystem.java
More file actions
212 lines (197 loc) · 9.12 KB
/
Copy pathOrderingSystem.java
File metadata and controls
212 lines (197 loc) · 9.12 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Dell
*/
public class OrderingSystem {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and feel.
}
ArrayList<Meal> meals = new ArrayList<Meal>();
meals.add(new Meal("Regular Burger",45));
meals.add(new Meal("Burger with Cheese",55));
meals.add(new Meal("Burger with egg and cheese",50));
meals.add(new Meal("Burger with ham",60));
meals.add(new Meal("Burger with ham and cheese",70));
meals.add(new Meal("Regular Fries",35));
meals.add(new Meal("Medium Fries",45));
meals.add(new Meal("Large Fries",55));
meals.add(new Meal("Choco Sundae",28));
meals.add(new Meal("Caramel Sundae",28));
meals.add(new Meal("Strawberry Sundae",28));
meals.add(new Meal("Regular Coke",25));
meals.add(new Meal("Large Coke",35));
meals.add(new Meal("Regular Sprite",28));
meals.add(new Meal("Large Sprite",38));
ArrayList<Order> orders = new ArrayList<Order>();
ArrayList<SalesReport> sales = new ArrayList<SalesReport>();
//password part
Password p = new Password("admin");
String[] options = new String[]{"Cancel", "Ok"};
PasswordPanel pnlPass = new PasswordPanel();
while (true){
int option = JOptionPane.showOptionDialog(null, pnlPass, "Login",
JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[1]);
if(option == 1){
String password = pnlPass.jPasswordField1.getText();
if (!password.equals(p.getPassword())){
p.tryAgain();
if (p.getTries() <= 0){
System.exit(0);
}
}else{
break;
}
}
}
System.out.print("Hello");
while (true){
MenuPanel m = new MenuPanel();
int menu = JOptionPane.showOptionDialog(null, m, "Menu",
JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[1]);
int menuChoice = m.jComboBox1.getSelectedIndex();
if(menu == 1){
if (menuChoice == 0){
OrderMealPanel op = new OrderMealPanel();
//converting arraylist to 2d array
Object[][] tbdata = new Object[meals.size()][3];
for (int i = 0; i < meals.size(); i++){
tbdata[i][0] = i;
tbdata[i][1] = meals.get(i).getMeal();
tbdata[i][2] = meals.get(i).getPrice();
}
op.jTable1.setModel(new javax.swing.table.DefaultTableModel(
tbdata,
new String [] {
"Meal ID#", "Meal", "Price"
}
));
int orderPanel = JOptionPane.showOptionDialog(null, op, "Order Meal",
JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[1]);
if(orderPanel == 1){
try{
String ordered_meal = meals.get(Integer.valueOf(op.txtMealID.getText())).getMeal();
double ordered_price = meals.get(Integer.valueOf(op.txtMealID.getText())).getPrice();
int quantity = Integer.valueOf(op.txtQuantity.getText());
orders.add(new Order(ordered_meal, ordered_price, quantity));
System.out.println(orders.get(0).getAmount());
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Invalid Input");
}
}
}else if(menuChoice == 1){
OrdersList ol = new OrdersList();
//converting arraylist to 2d array
Object[][] tbdata = new Object[orders.size()][5];
double totalAmount = 0;
for (int i = 0; i < orders.size(); i++){
tbdata[i][0] = i;
tbdata[i][1] = orders.get(i).getMeal();
tbdata[i][2] = orders.get(i).getPrice();
tbdata[i][3] = orders.get(i).getQuantity();
tbdata[i][4] = orders.get(i).getAmount();
totalAmount += orders.get(i).getAmount();
}
ol.jTable1.setModel(new javax.swing.table.DefaultTableModel(
tbdata,
new String [] {
"Order ID#", "Meal", "Price","Quantity","Amount"
}
));
ol.lblAmount.setText(String.valueOf(totalAmount));
ol.jButton1.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
private void jButton1ActionPerformed(ActionEvent evt) {
int id = Integer.valueOf(ol.txtOrderID.getText());
((DefaultTableModel)ol.jTable1.getModel()).removeRow(id);
orders.remove(id);
double newamount = 0;
for (int i = 0; i < orders.size(); i++){
newamount+=orders.get(i).getAmount();
}
ol.lblAmount.setText(String.valueOf(newamount));
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
int ordersPanel = JOptionPane.showOptionDialog(null, ol, "Order List",
JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[1]);
}
else if (menuChoice == 2){
ProcessPaymentPanel pay = new ProcessPaymentPanel();
double amount = 0;
for (int i = 0; i < orders.size(); i++){
amount+=orders.get(i).getAmount();
}
pay.txtAmount.setText(String.valueOf(amount));
int payPanel = JOptionPane.showOptionDialog(null, pay, "Process Payment",
JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[1]);
if (payPanel == 1){
double cash = Double.valueOf(pay.txtCash.getText());
double change = Double.valueOf(pay.txtChange.getText());
sales.add(new SalesReport(amount,cash,change));
orders.clear();
JOptionPane.showMessageDialog(null, "Transaction Saved!");
}
}else if(menuChoice == 3){
SalesReportPanel s = new SalesReportPanel();
Object[][] tbdata = new Object[sales.size()][4];
double total = 0;
for (int i = 0; i < sales.size(); i++){
tbdata[i][0] = i;
tbdata[i][1] = sales.get(i).getAmount();
tbdata[i][2] = sales.get(i).getCash();
tbdata[i][3] = sales.get(i).getChange();
total += sales.get(i).getAmount();
}
s.jTable1.setModel(new javax.swing.table.DefaultTableModel(
tbdata,
new String [] {
"Invoice ID", "Amount Paid for", "Cash","Change"
}
));
s.lblTotal.setText(String.valueOf(total));
JOptionPane.showOptionDialog(null, s, "Sales Report",
JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[1]);
}
else if(menuChoice == 4){
JOptionPane.showMessageDialog(null, "Logging out. Good Bye!");
break;
}
}
}
}
}