Skip to content

Commit 9fe6b61

Browse files
committed
added all committees
1 parent 5a2e73f commit 9fe6b61

File tree

4 files changed

+752
-0
lines changed

4 files changed

+752
-0
lines changed

cultural.java

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
package begin;
2+
3+
import java.io.BufferedWriter;
4+
import java.io.File;
5+
import java.io.FileInputStream;
6+
import java.io.FileOutputStream;
7+
import java.io.FileWriter;
8+
import java.io.IOException;
9+
import java.io.ObjectInputStream;
10+
import java.io.ObjectOutputStream;
11+
import java.util.Scanner;
12+
13+
public class cultural extends student{
14+
15+
private static final long serialVersionUID = 1L;
16+
static Scanner sc=new Scanner(System.in);
17+
18+
public int vote_for(student ob) throws IOException, ClassNotFoundException //function that will check whether candidate has voted or not.
19+
{
20+
student s=null;
21+
FileInputStream is = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\g_cultural_vote.txt"); // candidates who have given their vote in general cultural elections.
22+
while(is.available()>0)
23+
{
24+
ObjectInputStream ois = new ObjectInputStream(is);
25+
s = (student) ois.readObject();
26+
if(ob.ID==s.ID)
27+
{
28+
System.out.println("you have already voted.");
29+
return 1;
30+
}
31+
}
32+
33+
is.close();
34+
//candidate has not voted hence he will be allowed to vote
35+
36+
try
37+
{
38+
FileOutputStream fos = new FileOutputStream(new File("C:\\Users\\Dell\\Desktop\\project\\g_cultural_vote.txt"),true);
39+
ObjectOutputStream oos = new ObjectOutputStream(fos);
40+
int k=0;
41+
while(true)
42+
{
43+
System.out.println("1. vote");
44+
System.out.println("2. go back");
45+
int q=sc.nextInt();
46+
switch(q)
47+
{
48+
49+
case 1: try
50+
{
51+
vote(); //function that will allow the candidate to vote
52+
k=1; //if vote is successfull
53+
54+
oos.writeObject(ob);
55+
}
56+
catch (ClassNotFoundException e)
57+
{
58+
59+
e.printStackTrace();
60+
}
61+
catch (IOException e)
62+
{
63+
64+
e.printStackTrace();
65+
}
66+
break;
67+
case 2: k=1;
68+
break;
69+
70+
default: System.out.println("wrong choice...");
71+
}
72+
if(k==1)
73+
{
74+
break;
75+
}
76+
}
77+
oos.close();
78+
fos.close();
79+
}
80+
81+
catch (IOException e)
82+
{
83+
e.printStackTrace();
84+
}
85+
finally
86+
{
87+
// sc.close();
88+
}
89+
return 0;
90+
}
91+
92+
public static void vote() throws IOException, ClassNotFoundException
93+
{
94+
95+
FileInputStream is = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\c_selected.txt"); //going in c_selected to display the data of registered candidates
96+
97+
int count=0;
98+
student so=null;
99+
100+
while(is.available()>0)
101+
{
102+
ObjectInputStream ois1 = new ObjectInputStream(is); //reading the file to know number of registered candidates
103+
so= (student) ois1.readObject();
104+
count++;
105+
}
106+
is.close(); //
107+
108+
student s[]=new student[count]; //storing the student object data in an array
109+
110+
FileInputStream is1 = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\c_selected.txt");
111+
if(is1.available()==0)
112+
{
113+
System.out.println("no registered candidates yet.");
114+
return;
115+
}
116+
int i=0;
117+
int input;
118+
while(is1.available()>0)
119+
{
120+
ObjectInputStream ois = new ObjectInputStream(is1);// printing data
121+
s [i]= (student) ois.readObject();
122+
System.out.print("Candidate Number :"+ (i+1));
123+
System.out.print(" name : "+s[i].name);
124+
125+
System.out.print(" id : "+s[i].ID);
126+
127+
System.out.print(" batch : "+s[i].batch);
128+
129+
System.out.print(" branch : "+s[i].branch);
130+
131+
System.out.println();
132+
i++;
133+
}
134+
is1.close();
135+
136+
int k=0;
137+
while(true)
138+
{
139+
System.out.println("enter the candidate ID to vote for : ");
140+
input=sc.nextInt();
141+
for(int j=0;j<s.length;j++)
142+
{
143+
if(s[j].ID==input)
144+
{
145+
// s[j].c_comittee+=1; // c_comittee is for counting votes for selected candidates
146+
k=1;
147+
break;
148+
}
149+
}
150+
151+
if(k==1)
152+
{
153+
break;
154+
}
155+
else
156+
{
157+
System.out.println("you entered wrong ID please retry");
158+
}
159+
}
160+
try
161+
{
162+
BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\Users\\Dell\\Desktop\\project\\stats_gen_cult.txt", true) //Set true for append mode
163+
);
164+
//Add new line
165+
String h=Integer.toString(input);
166+
writer.write(h);
167+
writer.newLine();
168+
writer.close();
169+
System.out.println("Done");
170+
171+
172+
}
173+
catch (IOException e)
174+
{
175+
e.printStackTrace();
176+
}
177+
finally
178+
{
179+
// sc.close();
180+
}
181+
182+
183+
}
184+
185+
}
186+
187+
188+

literature.java

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
package begin;
2+
3+
import java.io.BufferedWriter;
4+
import java.io.File;
5+
import java.io.FileInputStream;
6+
import java.io.FileOutputStream;
7+
import java.io.FileWriter;
8+
import java.io.IOException;
9+
import java.io.ObjectInputStream;
10+
import java.io.ObjectOutputStream;
11+
import java.util.Scanner;
12+
13+
public class literature extends student{
14+
15+
private static final long serialVersionUID = 1L;
16+
static Scanner sc=new Scanner(System.in);
17+
18+
public int vote_for(student ob) throws IOException, ClassNotFoundException //function that will check whether candidate has voted or not.
19+
{
20+
student s=null;
21+
FileInputStream is = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\g_literature_vote.txt"); // candidates who have given their vote in general cultural elections.
22+
while(is.available()>0)
23+
{
24+
ObjectInputStream ois = new ObjectInputStream(is);
25+
s = (student) ois.readObject();
26+
if(ob.ID==s.ID)
27+
{
28+
System.out.println("you have already voted.");
29+
return 1;
30+
}
31+
}
32+
33+
is.close();
34+
//candidate has not voted hence he will be allowed to vote
35+
36+
try
37+
{
38+
FileOutputStream fos = new FileOutputStream(new File("C:\\Users\\Dell\\Desktop\\project\\g_literature_vote.txt"),true);
39+
ObjectOutputStream oos = new ObjectOutputStream(fos);
40+
int k=0;
41+
while(true)
42+
{
43+
System.out.println("1. vote");
44+
System.out.println("2. go back");
45+
int q=sc.nextInt();
46+
switch(q)
47+
{
48+
49+
case 1: try
50+
{
51+
vote(); //function that will allow the candidate to vote
52+
k=1; //if vote is successfull
53+
54+
oos.writeObject(ob);
55+
}
56+
catch (ClassNotFoundException e)
57+
{
58+
59+
e.printStackTrace();
60+
}
61+
catch (IOException e)
62+
{
63+
64+
e.printStackTrace();
65+
}
66+
break;
67+
case 2: k=1;
68+
break;
69+
70+
default: System.out.println("wrong choice...");
71+
}
72+
if(k==1)
73+
{
74+
break;
75+
}
76+
}
77+
oos.close();
78+
fos.close();
79+
}
80+
81+
catch (IOException e)
82+
{
83+
e.printStackTrace();
84+
}
85+
finally
86+
{
87+
// sc.close();
88+
}
89+
return 0;
90+
}
91+
92+
public static void vote() throws IOException, ClassNotFoundException
93+
{
94+
95+
FileInputStream is = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\l_selected.txt"); //going in c_selected to display the data of registered candidates
96+
97+
int count=0;
98+
student so=null;
99+
100+
while(is.available()>0)
101+
{
102+
ObjectInputStream ois1 = new ObjectInputStream(is); //reading the file to know number of registered candidates
103+
so= (student) ois1.readObject();
104+
count++;
105+
}
106+
is.close(); //
107+
108+
student s[]=new student[count]; //storing the student object data in an array
109+
110+
FileInputStream is1 = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\l_selected.txt");
111+
if(is1.available()==0)
112+
{
113+
System.out.println("no registered candidates yet.");
114+
return;
115+
}
116+
int i=0;
117+
int input;
118+
while(is1.available()>0)
119+
{
120+
ObjectInputStream ois = new ObjectInputStream(is1);// printing data
121+
s [i]= (student) ois.readObject();
122+
System.out.print("Candidate Number :"+ (i+1));
123+
System.out.print(" name : "+s[i].name);
124+
125+
System.out.print(" id : "+s[i].ID);
126+
127+
System.out.print(" batch : "+s[i].batch);
128+
129+
System.out.print(" branch : "+s[i].branch);
130+
131+
System.out.println();
132+
i++;
133+
}
134+
is1.close();
135+
136+
int k=0;
137+
while(true)
138+
{
139+
System.out.println("enter the candidate ID to vote for : ");
140+
input=sc.nextInt();
141+
for(int j=0;j<s.length;j++)
142+
{
143+
if(s[j].ID==input)
144+
{
145+
// s[j].c_comittee+=1; // c_comittee is for counting votes for selected candidates
146+
k=1;
147+
break;
148+
}
149+
}
150+
151+
if(k==1)
152+
{
153+
break;
154+
}
155+
else
156+
{
157+
System.out.println("you entered wrong ID please retry");
158+
}
159+
}
160+
try
161+
{
162+
BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\Users\\Dell\\Desktop\\project\\stats_gen_literature.txt", true) //Set true for append mode
163+
);
164+
//Add new line
165+
String h=Integer.toString(input);
166+
writer.write(h);
167+
writer.newLine();
168+
writer.close();
169+
System.out.println("Done");
170+
171+
172+
}
173+
catch (IOException e)
174+
{
175+
e.printStackTrace();
176+
}
177+
finally
178+
{
179+
// sc.close();
180+
}
181+
182+
183+
}
184+
}
185+
186+

0 commit comments

Comments
 (0)