-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.java
More file actions
436 lines (351 loc) · 8.19 KB
/
Copy pathdriver.java
File metadata and controls
436 lines (351 loc) · 8.19 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
package begin;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Scanner;
class cultural extends student{
private static final long serialVersionUID = 1L;
static Scanner sc=new Scanner(System.in);
public static int vote_for(student ob)
{
int k=0,ab=0;
while(true)
{
System.out.println("1. presidential voting");
System.out.println("2. vice-presidential voting");
System.out.println("3. general voting");
System.out.println("4. register as a candidate");
System.out.println("5. go back");
try {
ab=sc.nextInt();
}
catch(Exception e)
{
System.out.println(e);
}
switch(ab)
{
case 1: //presidential();
break;
case 2: //vice_presidential();
break;
case 3: general(ob);
break;
case 4: int i=register(ob);
if(i==1)
{
System.out.println("successfully registered.. ");
}
else if(i==0)
{
System.out.println("you have already registered");
}
break;
case 5: k=1;
break;
default: System.out.println("wrong choice...");
}
if(k==1)
{
break;
}
}
return 0;
}
public static void general(student ob)
{
int k=0;
while(true)
{
System.out.println("1. vote");
System.out.println("2. view details of regestered candidates");
System.out.println("3. go back");
int q=sc.nextInt();
switch(q)
{
case 1: // vote()
break;
case 2: try
{
view_details();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
break;
case 3: k=1;
break;
default: System.out.println("wrong choice...");
}
if(k==1)
{
break;
}
}
}
public static void view_details() throws IOException, ClassNotFoundException
{
student s=null;
FileInputStream is = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\c_selected.txt");
if(is.available()==0)
{
System.out.println("no regestered candidates yet.");
return;
}
while(is.available()>0)
{
ObjectInputStream ois = new ObjectInputStream(is);
s = (student) ois.readObject();
System.out.print(" name : "+s.name);
System.out.print(" id : "+s.ID);
System.out.print(" batch : "+s.batch);
System.out.print(" branch : "+s.branch);
System.out.print(" description : "+s.description);
System.out.print(" achievements : "+s.achievements);
System.out.println();
}
is.close();
}
public static int register(student ob)
{
if(ob.c_comittee==1)
{
return 0;
}
System.out.print("enter desciption : ");
ob.description=sc.next();
System.out.print("enter achivements : ");
ob.achievements=sc.next();
ob.c_comittee=1;
try
{
FileOutputStream fos = new FileOutputStream(new File("C:\\Users\\Dell\\Desktop\\project\\c_selected.txt"),true);
ObjectOutputStream oos = new ObjectOutputStream(fos);
// write object to file
oos.writeObject(ob);
System.out.println("Done");
oos.close();
fos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
// sc.close();
}
return 1;
}
}
class student implements Serializable
{
static Scanner sc=new Scanner(System.in);
private static final long serialVersionUID = 1L;
String name;
int ID;
String DOB;
String password;
int batch;
String branch;
long phone;
String e_mail;
String description;
String achievements;
int c_comittee;
public student()
{
name=null;
ID=0;
DOB=null;
password=null;
batch=0;
branch=null;
phone=0;
e_mail=null;
description=null;
achievements=null;
c_comittee=0;
}
public void input()
{
System.out.print("enter name : ");
this.name=sc.next();
System.out.print("enter id : ");
this.ID=sc.nextInt();
System.out.print("enter dob : ");
this.DOB=sc.next();
System.out.print("enter batch : ");
this.batch=sc.nextInt();
System.out.print("enter branch : ");
this.branch=sc.next();
System.out.print("enter phone : ");
this.phone=sc.nextLong();
System.out.print("enter email : ");
this.e_mail=sc.next();
System.out.print("enter password : ");
this.password=sc.next();
try
{
FileOutputStream fos = new FileOutputStream(new File("C:\\Users\\Dell\\Desktop\\project\\a.txt"),true);
ObjectOutputStream oos = new ObjectOutputStream(fos);
// write object to file
oos.writeObject(this);
System.out.println("Done");
oos.close();
fos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
// sc.close();
}
}
public void output() throws IOException, ClassNotFoundException
{
student s=null;
FileInputStream is = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\a.txt");
while(is.available()>0)
{
ObjectInputStream ois = new ObjectInputStream(is);
s = (student) ois.readObject();
System.out.print(" name : "+s.name);
System.out.print(" id : "+s.ID);
System.out.print(" dob : "+s.DOB);
System.out.print(" batch : "+s.batch);
System.out.print(" branch : "+s.branch);
System.out.print(" phone : "+s.phone);
System.out.print(" email : "+s.e_mail);
System.out.println();
}
is.close();
}
}
public class driver {
static Scanner sc=new Scanner(System.in);
public static void main_menu()
{
int u=0;
while(true)
{
System.out.println("welcome");
System.out.println("1. login");
System.out.println("2. exit");
int d=sc.nextInt();
switch(d)
{
case 1: login();
break;
case 2: u=1;
break;
default:System.out.println("you entered wrong choice");
}
if(u==1)
{
break;
}
}
}
public static void login()
{
while(true)
{
System.out.print("enter your ID : ");
int id=sc.nextInt();
System.out.println();
System.out.print("enter your password : ");
String pass=sc.next();
try
{
int i=check(id,pass);
if(i==2)
{
break;
}
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
public static int check(int id,String pass) throws IOException, ClassNotFoundException
{
student s=null;
int k=0;
FileInputStream is = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\a.txt");
while(is.available()>0)
{
ObjectInputStream ois = new ObjectInputStream(is);
s = (student) ois.readObject();
if(s.ID==id && s.password.compareTo(pass)==0)
{
System.out.println("correct details");
k=1;
break;
}
}
if(k==1)
{
options(s);
}
else
{
System.out.println("You entered wrong ID or Password...");
System.out.println("1. login again");
System.out.println("2. go back");
int input=sc.nextInt();
switch(input)
{
case 1: return 1; // login();
case 2: return 2; // main menu()
default: System.out.println("wrong choice...");
}
}
return 0;
}
public static void options(student ob)
{
System.out.println("1. cultural");
System.out.println("2. technical");
System.out.println("3. sports");
System.out.println("4. literature");
int input=sc.nextInt();
switch(input)
{
case 1: cultural c=new cultural();
c.vote_for(ob);
break;
case 2:
break;
case 3:
break;
case 4:
break;
default: System.out.println("wrong choice...");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
main_menu();
// student ob=new student();
// ob.input();
}
}