-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestFile.java
More file actions
296 lines (216 loc) · 11.4 KB
/
testFile.java
File metadata and controls
296 lines (216 loc) · 11.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
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
package project.pkg151;
//bonus#1
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.nio.file.Paths;
public class testFile {
public static void main(String [] args ) throws FileNotFoundException
{
//Array of all product by file
ArrayList<products> objproducts = new ArrayList <products> ();
Scanner sc = new Scanner(new File("pro.txt") );
while(sc.hasNext() )
{
String name ;
double price ;
objproducts.add(new products ( sc.next() , sc.nextDouble()) );
}
Scanner input = new Scanner (System.in ) ;
//Array of special product
ArrayList<products> listSp1 = new ArrayList <products> ();
listSp1.add(objproducts.get(0));
listSp1.add(objproducts.get(1));
listSp1.add(objproducts.get(2));
ArrayList<products> listSp2 = new ArrayList <products> ();
listSp2.add(objproducts.get(1));
listSp2.add(objproducts.get(3));
//
//object of special product get RelashtoinShip
special_product R = new special_product();
//Object of Store
store s = new store ("NICE Life");
//
//
//Araay of Employee
ArrayList<Employee> ListEmployee = new ArrayList <Employee> ();
sc = new Scanner(new File("employee.txt") );
while(sc.hasNext() )
{
String name ;
double salary ;
ListEmployee.add(new Employee( sc.next() , sc.nextDouble()) );
}
//object of custmer
customer c1 = new customer("ahmad");
customer c2 = new customer("amal");
System.out.println("----- Welcom in Happy Store " +s.getName() +" ------");
System.out.println("If are you custmer click c or are you manger click m ");
//use click to choose process custumer or Employee
char click = input.next().charAt(0);
if ( click == 'c')
{
System.out.println("-----Menu of Product Process ------");
try {
int choice = 0;
do {
System.out.println("1. Display all product ");
System.out.println("2. Display Special product");
System.out.println("3. check is Esixt ");
System.out.println("4. Cart & Buy ");
System.out.println("5. Exist");
System.out.println("Choice:");
choice = input.nextInt();
switch (choice) {
//Display all product
case 1:
System.out.println("it contains " + s.getArray1().size() + " Product in store");
for ( int i=0 ; i < s.getArray1().size() ; i++ ) {
System.out.println(s.getArray1().get(i));
}
break;
//Display Special product
case 2:
R.setReleationShip("1- offer 10% if buy all ");
for ( int i=0 ; i <listSp1.size() ; i++ ) {
System.out.println( R.getReleationShip() + listSp1.get(i).toString() );
}
R.setReleationShip("2- buy 1 get 1 free ");
for ( int i=0 ; i <listSp2.size() ; i++ ) {
System.out.println( R.getReleationShip() + listSp2.get(i).toString() );
}
break;
//check is Esixt
case 3:
System.out.print("Enter num of prodect ; " );
System.out.println( s.isExist(objproducts.get(input.nextInt()-1)));
break;
//Cart & Buy
case 4:
ArrayList<products> cart = new ArrayList <products> ();
System.out.println( " Enter num of prodect what you want buy if you finish click -1 : " );
int index = input.nextInt();
cart.add(objproducts.get(index - 1 ) );
for(int i = 0 ; i < cart.size() ; i++ ) {
System.out.println( " Enter num of prodect what you want buy if you finish click -1 : " );
index = input.nextInt();
if (index == -1 ) {
break;
}
else {
cart.add(objproducts.get(index - 1 ) );
for(products c : cart )
System.out.println(c); //add product in cart
}
}
System.out.println( s.totalPrice(cart)); //print total price of all product in cart
System.out.println( " If you agree to the price, press 1 to buy else press any number ");
int agree = input.nextInt();
if ( agree == 1 ){
s.buy(cart , c1 ); // buy product of cart
System.out.println( " visit after buy is " + c1.toString());
}
else
System.out.println( " again add product in cart ");
break;
case 5:
break;
default:
System.out.println("Sorry, please enter valid Option");
}
} while (choice != 5);
System.out.println("Thanks for you See you soon ");
} catch (Exception ex) {
System.out.println("Sorry not avaliable choice ");
input.nextInt();
} finally {
}
}// End of custmer process
else // Start process of Employee
if ( click == 'm') {
System.out.println(" Please Enter ID of Manger : ");
int idpass = input.nextInt();
if ( idpass == 1001 ) {
System.out.println("-----Menu of Product Process for Manger ------");
try {
int choice = 0;
do {
System.out.println("1. Display all product ");
System.out.println("2. Display Special product");
System.out.println("3. Add product");
System.out.println("4. Remove Product");
System.out.println("5. Display list of Employee" );
System.out.println("6. Update Salary of Employee");
System.out.println("7. Display list Custmer");
System.out.println("8. Exist");
System.out.println("Choice:");
choice = input.nextInt();
switch (choice) {
//Display all product
case 1:
System.out.println("it contains " + s.getArray1().size() + " Product in store");
for ( int i=0 ; i < s.getArray1().size() ; i++ ) {
System.out.println(s.getArray1().get(i));
}
break;
//Display Special product
case 2:
R.setReleationShip("1- offer in buy all ");
for ( int i=0 ; i <listSp1.size() ; i++ ) {
System.out.println( R.getReleationShip() + listSp1.get(i).toString() );
}
break;
//Add product
case 3:
System.out.println("Enter the name and price for the product ");
String n= input.next();
double cost = input.nextDouble();
s.addProduct(new products(n,cost));
System.out.println(s.getArray());
break;
//Remove Product
case 4:
store e= new store();
e.setArray(objproducts);
e.textArea.setText(e.getArray());
break;
//Display list of Employee
case 5:
for ( int i=0 ; i < ListEmployee.size() ; i++ ) {
System.out.println(ListEmployee.get(i).toString());
}
break;
//Update Salary of Employee
case 6:
System.out.println(" Update percentage number ");
int update = input.nextInt();
System.out.println(" please Enter the last numebr in ID of The "
+ "employee whose salary you want to increase : ");
int indexEmployee = input.nextInt();
ListEmployee.get(indexEmployee - 1).UpdateSalary(update);
System.out.println("the Salary after Update :" + ListEmployee.get(indexEmployee - 1).toString());
break;
//Display list Custmer
case 7:
System.out.println( c1.toString() +"\n"+ c2.toString() );
break;
case 8:
break;
default:
System.out.println("Sorry, please enter valid Option");
}
} while (choice!= 8);
System.out.println(" End process ");
} catch (Exception ex) {
System.out.println("Sorry not avaliable choice ");
input.nextInt();
} finally {
System.out.println("Thanks you ");
}
}
}
else
System.out.println(" NOT correct option ");
}
}