-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
230 lines (186 loc) · 9.13 KB
/
Main.java
File metadata and controls
230 lines (186 loc) · 9.13 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
229
package shopping;
import java.util.List;
import java.util.Scanner;
public class Main {
public static String chooseForCase(String choose){
int index=-1;
String[] Dic = {"Add WebUser","Exit","Remove WebUser","Login WebUser","Logout WebUser","Make order","Display order","Link Product","Add Product","Delete Product","ShowAllObjects","ShowObjectId" };
for (int i=0; i<Dic.length; i++){
if(choose.startsWith(Dic[i])) {
index = i;
break;
}
}
if (index != -1)
return Dic[index];
else
return "Default";
}
public static void main(String[] args) {
ShoppingSystem shoppingSystem = new ShoppingSystem();
boolean flag = true;
while (flag){
Scanner myObj = new Scanner(System.in);
System.out.println("Please enter one of the following commnads:\n1.Add WebUser *Login_id*" +
"\n2.Remove WebUser *Login_id*\n3.Login WebUser *Login_id*\n4.Logout WebUser *Login_id*" +
"\n5.Make order\n6.Display order\n7.Link Product *Product_name*\n8.Add Product " +
"\n9.Delete Product *Product_name*\n10.ShowAllObjects\n11.ShowObjectId *id*\n12.Exit");
String choose = myObj.nextLine();
String command = chooseForCase(choose);
String[] listChoose = choose.split(" ");
switch (command){
case "Add WebUser":
String id = listChoose[2];
// Arg Web User
System.out.println("Enter Password");
String Password = myObj.nextLine();
// Arg Customer
System.out.println("Enter country");
String country = myObj.nextLine();
System.out.println("Enter City");
String city = myObj.nextLine();
System.out.println("Enter Street");
String Street = myObj.nextLine();
System.out.println("Enter Phone");
String Phone = myObj.nextLine();
System.out.println("Enter Email");
String Email = myObj.nextLine();
// Arg Account
System.out.println("Enter Billing Address");
String billingAddress = myObj.nextLine();
System.out.println("Enter your balance (integer)");
String balanceString = myObj.nextLine();
System.out.println("Are you a Premium Account? yes/no");
String premium_account = myObj.nextLine();
premium_account=premium_account.toLowerCase();
int balance = Integer.parseInt(balanceString);
Boolean premiumAccount;
if(premium_account.equals("yes")){
premiumAccount=true;
}
else {
premiumAccount = false;
}
shoppingSystem.addWebUser(id,Password,country,city,balance,Street,Phone,Email,billingAddress,premiumAccount);
break;
case "Remove WebUser":
String idRemove = listChoose[2];
shoppingSystem.removeWebUser(idRemove);
break;
case "Login WebUser":
Boolean connected = false;
String loginId = listChoose[2];
String loginIdActive = shoppingSystem.getActiveUser();
if(loginIdActive.equals("")){
while (!connected){
System.out.println("Enter Password");
String password = myObj.nextLine();
connected = shoppingSystem.verifyLogin(loginId,password);
}
}
else if(loginIdActive.equals(loginId)){
System.out.println("You are already login");
}
else {
System.out.println("wait for"+ loginIdActive+"to log off");
}
break;
case "Logout WebUser":
String logOutId = listChoose[2];
String loginIdActiveNow = shoppingSystem.getActiveUser();
if( loginIdActiveNow.equals(logOutId)){
shoppingSystem.logOut(logOutId);
System.out.println("Bye bye...");
}
else if(loginIdActiveNow.equals("")){
System.out.println("No one's login");
}
else {
System.out.println("you are wrong in userId");
}
break;
case "Make order":
shoppingSystem.updateShoppingCartDate();
System.out.println("Enter Seller Name");
String nameseller = myObj.nextLine();
List<Product> listProduct = shoppingSystem.showSellerProduct(nameseller);
for (int i=0; i <listProduct.size() ;i++){
Product product = listProduct.get(i);
System.out.println(product);
}
Boolean flagProudct=false;
while (!flagProudct){
System.out.println("please choose a product:");
String product =myObj.nextLine();
System.out.println("Enter quantity:");
String quantityScanner =myObj.nextLine();
int quantity = Integer.parseInt(quantityScanner);
Product p1 = null;
for(int i = 0 ; i< listProduct.size();i++){
if (product.equals((listProduct.get(i)).getName())){
p1=listProduct.get(i);
}
}
shoppingSystem.addToShoppingCart(p1,quantity);
System.out.println("you want more product? Y/N");
String nextItem =myObj.nextLine();
if (nextItem.equals("N"))
flagProudct=true;
}
Boolean isDelayed = false;
System.out.println("enter one of the following:\n" +
"DelayedPayment or ImmediatePayment ");
String pay = myObj.nextLine();
if(pay.equals("DelayedPayment"))
isDelayed=true;
System.out.println("How many payments would you like?");
String numPay = myObj.nextLine();
int numOfPayments = Integer.parseInt(numPay);
shoppingSystem.makeOrder(isDelayed, numOfPayments);
break;
case "Display order":
System.out.println(shoppingSystem.getLastOrder().toString());
break;
case "Link Product":
String Product_name = listChoose[2];
System.out.println("Enter quantity");
String quantity = myObj.nextLine();
int quantity1 =Integer.parseInt(quantity);
System.out.println("Enter price");
String price = myObj.nextLine();
int price1 =Integer.parseInt(price);
shoppingSystem.addProductToAccount(Product_name,quantity1,price1);
break;
case "Add Product":
System.out.println("Enter product name");
String NameNewPro = myObj.nextLine();
System.out.println("Enter ID");
String productID = myObj.nextLine();
System.out.println("Enter Supplier");
String SupplierName = myObj.nextLine();
System.out.println("Enter SupplierID");
String SupplierID = myObj.nextLine();
shoppingSystem.addProduct(NameNewPro,productID,SupplierName,SupplierID);
break;
case "Delete Product":
String ProductNameDelete = listChoose[2];
shoppingSystem.DeleteProduct(ProductNameDelete);
System.out.println("Product deleted");
break;
case "ShowAllObjects":
shoppingSystem.showAllObjects();
break;
case "ShowObjectId":
String idObjectString = listChoose[1];
int idObject = Integer.parseInt(idObjectString);
shoppingSystem.showObjectId(idObject);
break;
case "Exit":
flag = false;
break;
default:
System.out.println("Please try again");
}
}
}
}