-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadInput.java
306 lines (291 loc) · 10.1 KB
/
ReadInput.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import java.util.*;
/**
* Write a description of class ReadInput here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ReadInput
{
/**
* A default constructor for objects of class ReadInput
*/
public ReadInput()
{
}
/**
* Create a readProductAmount method to read the Product Amount.
*/
public double readProductAmount()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter product amount(Enter \"X\" to cancel):");
String amount = console.nextLine().trim();
if (amount.equals("x") || amount.equals("X"))
return -1;
while (!valide.validateProductAmount(amount))
{
amount = console.nextLine().trim();
if (amount.equals("x") || amount.equals("X"))
return -1;
}
return Double.valueOf(amount);
}
/**
* Create a readProductCategory method to read the Product Category.
*/
public String readProductCategory()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter product category(fruit or vagetable)(Enter \"X\" to cancel):");
String category = console.nextLine().trim();
if (category.equals("x") || category.equals("X"))
return "X";
while (!valide.validateProductCategory(category))
{
category = console.nextLine().trim();
if (category.equals("x") || category.equals("X"))
return "X";
}
return category;
}
/**
* Create a readProductDiscount method to read the Product Discount.
*/
public double readProductDiscount()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter product discount(Enter \"X\" to cancel):");
String discount = console.nextLine().trim();
if (discount.equals("x") || discount.equals("X"))
return -1;
while (!valide.validateProductDiscount(discount))
{
discount = console.nextLine().trim();
if (discount.equals("x") || discount.equals("X"))
return -1;
}
return Double.valueOf(discount);
}
/**
* Create a readProductExchangeAmount method to read the Product Exchange Amount.
*/
public String readProductExchangeAmount(String unit)
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter product exchange amount(1 " + unit + " equals to how many inventory unit)(Enter \"X\" to cancel):");
String amount = console.nextLine().trim();
if (amount.equals("x") || amount.equals("X"))
return "X";
while (!valide.validateProductAmount(amount))
{
amount = console.nextLine().trim();
if (amount.equals("x") || amount.equals("X"))
return "X";
}
return amount;
}
/**
* Create a readProductName method to read the Product Name.
*/
public String readProductName()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter product name(Enter \"X\" to cancel):");
String name = console.nextLine().trim();
if (name.equals("x") || name.equals("X"))
return "X";
while (!valide.validateProductName(name))
{
name = console.nextLine().trim();
if (name.equals("x") || name.equals("X"))
return "X";
}
return name;
}
/**
* Create a readProductOrigin method to read the Product Origin.
*/
public String readProductOrigin()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter product origin(Enter \"X\" to cancel):");
String origin = console.nextLine().trim();
if (origin.equals("x") || origin.equals("X"))
return "X";
while (!valide.validateProductOrigin(origin))
{
origin = console.nextLine().trim();
if (origin.equals("x") || origin.equals("X"))
return "X";
}
return origin;
}
/**
* Create a readProductPrice method to read the Product Price.
*/
public String readProductPrice()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter price(Enter \"X\" to cancel):");
String price = console.nextLine().trim();
if (price.equals("x") || price.equals("X"))
return "X";
while (!valide.validateProductPrice(price))
{
price = console.nextLine().trim();
if (price.equals("x") || price.equals("X"))
return "X";
}
return price;
}
/**
* Create a readProductShelfLife method to read the Product Shelf Life.
*/
public int readProductShelfLife()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter product shelf life(Enter \"X\" to cancel):");
String shelfLife = console.nextLine().trim();
if (shelfLife.equals("x") || shelfLife.equals("X"))
return -1;
while (!valide.validateProductShelfLife(shelfLife))
{
shelfLife = console.nextLine().trim();
if (shelfLife.equals("x") || shelfLife.equals("X"))
return -1;
}
return Integer.valueOf(shelfLife);
}
/**
* Create a readPurchaseOption method to read the input purchase option.
*/
public String readPurchaseOption()
{
Validation valide = new Validation();
Scanner console = new Scanner(System.in);
String option = console.nextLine().trim();
while (!valide.validateInteger(option))
option = console.nextLine().trim();
return option;
}
/**
* Create a readUserAddress method to read the User Address.
*/
public String readUserAddress()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter your address(Enter \"X\" to cancel):");
String address = console.nextLine().trim();
if (address.equals("x") || address.equals("X"))
return "X";
while (!valide.validateUserAddress(address))
{
address = console.nextLine().trim();
if (address.equals("x") || address.equals("X"))
return "X";
}
return address;
}
/**
* Create a readUserEmail method to read the user Email.
*/
public String readUserEmail()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter your email(Enter \"X\" to cancel):");
String email = console.nextLine().trim();
if (email.equals("x") || email.equals("X"))
return "X";
while (!valide.validateUserEmail(email))
{
email = console.nextLine().trim();
if (email.equals("x") || email.equals("X"))
return "X";
}
return email;
}
/**
* Create a readUserName method to read the user name.
*/
public String readUserName()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter your name(Enter \"X\" to cancel):");
System.out.println("Your name format could be \"Given name\"-\"Family name\",whthout whitespace!");
System.out.println("Your name can't be less than two characters,at most one \"-\" in the middle.");
String name = console.nextLine().trim();
if (name.equals("X") || name.equals("x"))
{
return "X";
}
while (!valide.validateUserName(name))
{
name = console.nextLine().trim();
if (name.equals("X") || name.equals("x"))
return "X";
}
return name;
}
/**
* Create a readUserPassword method to read the User Password.
*/
public String readUserPassword()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter your password(Enter \"X\" to cancel):");
String password = console.nextLine().trim();
if (password.equals("x") || password.equals("X"))
return "X";
while (!valide.validatePassword(password))
{
password = console.nextLine().trim();
if (password.equals("x") || password.equals("X"))
return "X";
}
return password;
}
/**
* Create a readUserPhone method to read the User Phone.
*/
public String readUserPhone()
{
Scanner console = new Scanner(System.in);
Validation valide = new Validation();
System.out.println("Please enter your phone number(Enter \"X\" to cancel):");
String phone = console.nextLine().trim();
if (phone.equals("x") || phone.equals("X"))
return "X";
while (!valide.validateUserPhone(phone))
{
phone = console.nextLine().trim();
if (phone.equals("x") || phone.equals("X"))
return "X";
}
return phone;
}
/**
* Create a readYNOption method to read the input choice (yes or no).
*/
public String readYNOption()
{
Validation valide = new Validation();
Scanner console = new Scanner(System.in);
String option = console.nextLine().trim().toUpperCase();
while (!valide.validateYN(option))
option = console.nextLine().trim().toUpperCase();
return option;
}
}