-
Notifications
You must be signed in to change notification settings - Fork 0
/
Votingsystem.java
90 lines (72 loc) · 1.98 KB
/
Votingsystem.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
import java.util.Scanner;
public class Votingsystem
{
public static void displayResult()
{
Scanner asa = new Scanner(System.in);
float total=a + b + c;
System.out.println("\nPRESIDENTIAL ELECTION");
System.out.println("Candidates\tResult\t% of Total Votes");
System.out.println("\nA: Dheyaraj Kavar\t" + a + "\t" + a/total * 100);
System.out.println("B: Sanjay Tare\t" + b + "\t" + b/total * 100);
System.out.println("C: Abhishek Mane\t\t" + c + "\t" + c/total * 100);
System.out.println("\nTOTAL VOTES: " + total);
String winner="";
if(a>b && a>c)
winner="Dheyaraj Kavar";
if(b>a && b>c)
winner="Sanjay Tare";
if(c>a && c>b)
winner="Abhishek Mane";
System.out.println("\nAnd the winner is: " + winner);
System.out.println("----------------------");
System.out.println("Type V-vote, R-result, Q-quit");
System.out.print("Enter your choice: ");
choice = asa.nextLine();
}
public static void displayVote()
{
Scanner asa = new Scanner(System.in);
System.out.print("Enter your vote: ");
candid = asa.next();
candidcode = candid.charAt(0);
switch(candidcode)
{
case 'A':
case 'a': a++; break;
case 'B':
case 'b': b++; break;
case 'C':
case 'c': c++; break;
default: System.out.println("Invalid candidates code");
}
}
static String choice, candid;
static char candidcode;
static int a=0, b=0, c=0;
public static void main( String[] args )
{
Scanner asa = new Scanner(System.in);
do
{
System.out.println("\nPRESIDENTIAL ELECTION");
System.out.println("Candidates");
System.out.println("\nA: Dheyaraj Kavar");
System.out.println("B: Sanjay Tare");
System.out.println("C: Abhishek Mane");
System.out.println("----------------------");
System.out.println("Type V-vote, R-result, Q-quit");
System.out.print("Enter your choice: ");
choice = asa.nextLine();
if(choice.equalsIgnoreCase("V"))
{
displayVote();
}
if(choice.equalsIgnoreCase("R"))
{
displayResult();
}
}
while(!(choice.equalsIgnoreCase("Q")));
}
}