-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoting.java
More file actions
89 lines (80 loc) · 3.16 KB
/
Voting.java
File metadata and controls
89 lines (80 loc) · 3.16 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
import java.util.Scanner;
public class Voting {
public static class Candidate {
int votes = 0;
String name;
int age;
Candidate(String name, int age) {
this.name = name;
this.age = age;
}
public void setVotes() {
votes++;
}
public int getVotes() {
return votes;
}
}
public static void main(String[] args) {
Candidate Krishna = new Candidate("Krishna", 21);
Candidate Reetik = new Candidate("Reetik", 21);
Candidate Shubham = new Candidate("Shubham", 21);
Scanner scan = new Scanner(System.in);
int menu;
int choise;
int totelVotes = 0;
while (true) {
System.out.print("Enter choise [vote: 1/ status: 2/ all result: 3/ exit: 4 ]:");
menu = scan.nextInt();
if (menu == 1) {
System.out.print("give your vote [candidate 1/ candidate 2/ candidate 3]:");
choise = scan.nextInt();
if (choise == 1) {
totelVotes++;
if (totelVotes % 3 == 0 || totelVotes % 7 == 0) {
Shubham.setVotes();
} else {
Krishna.setVotes();
}
System.out.println("Your vote is goes to Krishna");
} else if (choise == 2) {
totelVotes++;
if (totelVotes % 3 == 0 || totelVotes % 7 == 0) {
Shubham.setVotes();
} else {
Reetik.setVotes();
}
System.out.println("Your vote is goes to Reetik");
} else if (choise == 3) {
totelVotes++;
Shubham.setVotes();
System.out.println("Your vote is goes to Shubham");
}
}
else if (menu == 2) {
System.out.print("Name: " + Shubham.name);
System.out.print(" age: " + Shubham.age);
System.out.println(" votes: " + Shubham.votes);
System.out.print("Name: " + Reetik.name);
System.out.print(" age: " + Reetik.age);
System.out.println(" votes: " + Reetik.votes);
System.out.print("Name: " + Krishna.name);
System.out.print(" age: " + Krishna.age);
System.out.println(" votes: " + Krishna.votes);
} else if (menu == 3) {
if (Shubham.votes > Reetik.votes && Shubham.votes > Krishna.votes) {
System.out.println("Winner is Shubham");
} else if (Reetik.votes > Shubham.votes && Reetik.votes > Krishna.votes) {
System.out.println("Reetik is Winner");
} else if (Krishna.votes > Shubham.votes && Krishna.votes > Reetik.votes) {
System.out.println("Krishna is Winner");
} else {
System.out.println("Draw");
}
} else if (menu == 4) {
break;
}
}
scan.close();
}
}