-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.java
More file actions
102 lines (95 loc) · 4.4 KB
/
Copy pathmain.java
File metadata and controls
102 lines (95 loc) · 4.4 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
// FCAI – Intro to Software Engineering – 2022-2023 - Assignment 3
// Program Name: Toffe Store
// Last Modification Date: 13/5/2023
// Author1 and ID: Rawan Hesham Hamdy ID: 20211040
// Author2 and ID: Marwa Sameh Mostafa ID: 20210514
// Author3 and ID: Asmaa Elawady Ibrahim ID: 20210068
// description: progarm for a candy store called Toffee Store.
import java.io.IOException;
import java.util.*;
public class main {
public static void main(String[] args) throws IOException {
GeneralUser generalUser = new GeneralUser();
LoggedInUser loggedUser = new LoggedInUser();
shoppingCart cart = new shoppingCart();
store store = new store();
store.storeCatg();
String data[];
String user = "General";
int choice = 0;
while (user == "General" && choice != 5) {
Scanner sc = new Scanner(System.in);
System.out.println("\n*********Welcome to Toffee Store*********\n");
System.out.println("1- log in.");
System.out.println("2- Register.");
System.out.println("3- View Categories.");
System.out.println("4- Search for Item.");
System.out.println("5- Exit.");
System.out.print("What do you want to do? choose a number (1, 2, 3, 4, or 5): ");
choice = sc.nextInt();
if (choice == 1) {
data = new String[7];
data = generalUser.logIn();
if (data[0] == null) {
System.out.println("invalid username or password");
System.out.println("please try again");
data = generalUser.logIn();
}
loggedUser = new LoggedInUser(data);
loggedUser.setShoppingCart(cart);
cart.loadItemsFromCart(loggedUser);
user = "logged";
} else if (choice == 2) {
data = new String[5];
data = generalUser.register();
loggedUser = new LoggedInUser(data);
loggedUser.setShoppingCart(cart);
user = "logged";
} else if (choice == 3) {
store.viewCategories("general");
System.out.println("To start Shopping you must login or register if it is your first time");
} else if (choice == 4) {
// generalUser.searchForItem();
System.out.println("Enter the item's name: ");
store.search("general");
System.out.println("To start Shopping you must login or register if it is your first time");
} else if (choice == 5) {
return;
}
}
while (choice != 6) {
Scanner sc = new Scanner(System.in);
System.out.println("\n*********Welcome " + loggedUser.getUserName() + "*********\n");
System.out.println("1- View Categories.");
System.out.println("2- Search for Item.");
System.out.println("3- View Shopping Cart.");
System.out.println("4- Remove item from Shopping Cart.");
System.out.println("5- Make an order.");
System.out.println("6- Exit.");
System.out.print("What do you want to do? choose a number (1, 2, 3, 4, 5, or 6): ");
choice = sc.nextInt();
if (choice == 1) {
item cartitem = new item();
cartitem = store.viewCategories("loggedin");
loggedUser.getCart().addItem(cartitem, loggedUser);
} else if (choice == 2) {
// loggedUser.sea1rchForItem();
item cartitem = new item();
cartitem = store.search("loggedin");
loggedUser.getCart().addItem(cartitem, loggedUser);
} else if (choice == 3) {
System.out.println("Viewing " + loggedUser.getName() + "'s Shopping Cart");
loggedUser.getCart().displayShoppingCartItems();
} else if (choice == 4) {
System.out.println("Enter the item you want to remove from the cart");
String s = sc.next();
loggedUser.getCart().removeItem(s);
} else if (choice == 5) {
System.out.println("\n" + loggedUser.getName() + "'s Shpping Cart\n");
loggedUser.makeAnOrdrer();
} else if (choice == 6) {
return;
}
}
}
}