Write a Program in Java to make the Voting System
VOTER
import java.io.*;
public class vote {
    public static void
main(String[] args) {
       
DataInputStream in=new DataInputStream(System.in);
        int choice,v1=0,v2=0,v3=0,v;
       
try{
        do
        {
           
System.out.println("1:M.Shirodkar\n2: D.Shet \n3:D.Desai”);
            System.out.println("0:End
of voting phase");
           
choice=Integer.parseInt(in.readLine());
           
switch(choice)
           
{
               
case 1:
                   
v1++;
                   
break;
               
case 2:
                
   v2++;
                   
break;
               
case 3:
                   
v3++;
                   
break;
                
  System.out.println("Please vote for the given
candidates only:");
                   
System.out.println("Vote again:");
                   
break;
           
}
       
}while(choice!=0);
       
v=v1+v2+v3;
       
System.out.println("Total number of votes casted are:"+v);
       
System.out.println("No.        Candidate Name         
Votes");
       
System.out.println("1         
M.Shirodkar             
"+v1);
       
System.out.println("2          D. Shet                
"+v2);
       
System.out.println("3         
D.Desai            
"+v3);
       if(v1>v2&&v1>v3)
           
System.out.println("The Winner is M.Shirodkar");
       
else if(v1<v2&&v3<v2)
           
System.out.println("The winner is D. Shet ");
       
else if(v3>v2&&v1<v3)
           
System.out.println("The Winner is  D.Desai");
        }
       
catch(Exception q){}
    }
}
OUTPUT
C:\Program
Files\Java\jdk1.5.0\bin>java vote
1:M.
2: D.
3:D.
0:End of voting phase
1
1:M.
2: D.
3:D.
0:End of voting phase
3
1:M. Shirodkar 
2: D. Shet
3:D.
0:End of voting phase
1
1:M.
2: D.
3:D.
0:End of voting phase
0
Total number of votes
casted are:3
Number of spoiled
ballots are:0
No.       
Candidate Name          Votes
1         
M. Shirodkar                       2
2          D. Shet             
                    0
3          D.Desai                                 1
The Winner is
M.
 

 
 
 
 
 
 
 
 
 

No comments:
Write comments