forked from Izaiah-M/CakeShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomerMain.java
210 lines (164 loc) · 7.74 KB
/
CustomerMain.java
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
package CakeShop;
import java.util.Scanner;
import java.sql.SQLException;
public class CustomerMain {
final static Scanner scanner = new Scanner(System.in);
protected static Customer customer;
protected static Sales sale;
public static void main(String[] args) throws SQLException {
CustomerDashboard();
// When a customer is created
// They should be instantiated with a shopping cart object DONE
// The shopping cart object should take in a cake object DONE
// Cakes are our items and are added into the cart DONE
// When the info of the customer is passed in they see the cake data base items,
// DONE
// they pick items they need
// items are added or removed from the cart
// Check out receipt is generated.
}
private static boolean SignIn() throws SQLException {
// login with a password to be implemented but needs the customer table in the
// database to include a password column DONE
Login login = new Login();
System.out.println("Enter your email: ");
String email = scanner.nextLine();
System.out.println("Enter your password: ");
String password = scanner.nextLine();
login.setEmail(email);
login.setPassword(password);
// the DatabaseConnect.CustomerSignIn() method returns a customer object
// we will access the shopping cart of this customer object later on when the
// customer is ordering
customer = DatabaseConnect.CustomerSignIn(login);
if (customer != null) {
return true;
}
return false;
}
public static Customer AddCustomerInfo() throws SQLException {
System.out.println("Welcome to our Cake Shop");
System.out.println("Enter your name:");
String customername = scanner.nextLine();
System.out.println("Enter your email:");
String customeremail = scanner.nextLine();
System.out.println("Enter your contact:");
int customercontact = scanner.nextInt();
scanner.nextLine();
System.out.println("Enter your address:");
String customeraddress = scanner.nextLine();
System.out.println("Enter your new password:");
String customerpassword = scanner.nextLine();
Customer cs = new Customer(customername, customeremail, customercontact, customeraddress, customerpassword);
DatabaseConnect.AddCustomer(cs);
return cs;
}
public static void CustomerDashboard() throws SQLException {
System.out.println("Welcome to our Cake shop");
System.out.println("1.Sign Up");
System.out.println("2.Sign In");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
// this is used to add a customers, information to the database
customer = AddCustomerInfo();
CustomerMenu();
break;
case 2:
// this is used to check for a customers information from the database
// we keep on
boolean signIn;
do {
signIn = SignIn();
if (signIn == true) {
CustomerMenu();
} else {
System.out.println("Please sign in with the correct credentials or Sign up");
}
} while (signIn == false);
break;
}
}
public static void CustomerMenu() throws SQLException {
System.out.println("Catalog and Custom Order");
System.out.println("Do you want to See the catalog or make a custom order");
System.out.println("1. See Catalog");
System.out.println("2. Make a custom Order");
System.out.println("3. Check Your Cart\n");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
// TODO work on adding items to cart from the catalog
CatalogInfo catalog = DatabaseConnect.GenerateCatalog();
System.out.println("-----------------------Catalog-----------------------");
System.out.println(catalog.getCakeList());
// TODO implementing a function where customers can see the catalog and choose
// an item from it and on choosing to buy that item, the item is removed from
// the database
// when a customer enters the id of the cake, we run the getCake method of the
// catalog class and return that cake from the list
// we then add that item to the shopping cart.
System.out.println("Which Cake would you like to purchase from the catalog?(Enter the cake's Id)");
int CakeChoice = scanner.nextInt();
scanner.nextLine();
Cakes answer = catalog.getCake(CakeChoice);
if (answer == null) {
System.out.println("Cake not found");
} else {
ShoppingCartItem cake = new ShoppingCartItem(answer);
customer.cart.addItem(cake);
System.out.println(customer.getCart());
// make a new sales object and then pass it to the database
// this is just a test to see if the cakes go to the sales database when the
// sale is made
sale = new Sales(answer);
DatabaseConnect.AddNewSale(sale);
}
break;
case 2:
// here the customer creates their own cake object and it is then returned from
// the CustomerOrdering method
Cakes CustomerOrder = CustomerOrdering();
System.out.println(CustomerOrder);
break;
case 3:
System.out.println(customer.getCart());
break;
default:
break;
}
}
public static Cakes CustomerOrdering() throws SQLException {
String Ctype = null, Cflavour = null, Cdate = null, Cicing = null, Cmessage = null;
int Cprice = 0;
System.out.println("Enter the type of the cake i.e fruit cake, forest cake, sponge cake, basic vanilla cake");
Ctype = scanner.nextLine();
System.out.println("Enter the flavour of the cake e.g orange, marble , chocolate ,vanilla");
Cflavour = scanner.nextLine();
System.out.println("Enter the icing type of the cake i.e fondant , whipped cream , butter cream");
Cicing = scanner.nextLine();
System.out.println("Enter the message you want on the cake.");
Cmessage = scanner.nextLine();
System.out.println("Enter the price of the cake ");
Cprice = scanner.nextInt();
scanner.nextLine();
System.out.println("Enter the date when you want the cake.");
Cdate = scanner.nextLine();
// So here the custom order is made
Cakes customOrder = new Cakes(Ctype, Cflavour, Cmessage, Cdate, Cicing, Cprice);
// Then here the custom order is passed as our shopping cart Item cause remember
// our shopping Cart Item can also take in a Cake Object
ShoppingCartItem cake = new ShoppingCartItem(customOrder);
// Then here, that item, is passed into the cart, our ShoppingCart takes in
// objects of ShopppingcartItem
customer.cart.addItem(cake);
// i think we can return the cake that the customer ordered for
return customOrder;
}
// Removing from cart
// If customer choses cake to remove
// we pick the cake he wants to remove by id
// then delete it/remove it from cart
}