ElectionCentraljava Can you please help me the JAVA program

ElectionCentral.java

Can you please help me the JAVA program?

The people of the town of Dante are voting today, and they need a voting system. Your mission is to create a voting application. They want voting machines that take a slate of candidates. They want a machine that will allow users to vote, tally their votes, and print the results. Your application should support two voting machines. Your user interaction might look like this (assuming the machine was created with candidates \"boor, \" \"crook, \" and \"tree hugger\"). Do you wish to vote(1), or end the program(0)? 1 Do you wish to use machine 1 or machine 2? 2 Do you wish to vote for boor(1) crook(2) or tree hugger(3)? 2 Do you wish to vote(1), or end the program(0)? 1 Do you wish to use machine 1 or machine 2? 1 Do you wish to vote for boor(1) crook(2) or tree hugger(3)? 3 Do you wish to vote(1), or end the program(0)? 0 machine 1 votes: boor 0, crook 0, tree hugger 1 machine 2 votes: boor 0, crook 1, tree hugger 0 To get started, consider the following questions: What are the major nouns of the scenario? user, vote, machine, candidate, results What are the relationships between these nouns? users cast votes that are counted by a machine a machine prints its results Write a program to implement this scenario. Use two classes. One class should contain a main method and manage the dialog with the user. The other class should represent a voting machine. The design of the voting machine\'class is up to you. Make sure that your instance variables are private, follow the naming conventions, etc.

Solution

/* Java Programme for voting system */
import java.util.Scanner;           //scanner class to read input
import java.io.*;                   //imprt io package
public class vote               //Grades class creation
{
   public static void main(String args[])   throws IOException       //Main method of class ,programme execution begins by calling this method
   {
   Scanner sc=new Scanner(System.in);           //scanner class object sc creation
   VotingSystem vs=new VotingSystem();           //Object Creation for voting system class
   while(true)                                   //loop repeats until end of programme option (0)
       {
       System.out.println(\"Do you Wish to Vote(1),End of Programme(0)\");   //prompt for vote or end
       int willing=sc.nextInt();                                           //read choice
       if(willing==0)                                                       //if choice close break
           break;
       System.out.println(\"Do you Wish to use Machine(1) or Machine(2)\");               //prompt for use machine1 /machine2
       int machine=sc.nextInt();                                                       //read choice
       System.out.println(\"Do you Wish to vote Boor(1) or Crocky(2) or hugger[3]\");       //prompt for vote
       int candidate=sc.nextInt();                                                       //read choice
      
       vs.savevote(machine,candidate);                                                   //call save vote function to save choices

       }
       System.out.println(\"Machine 1 Votes\\t boor\"+vs.boor1+\",\\t crocky \"+vs.crocky1 +\",\\t hugger\"+vs.hugger1+\"\ \");           //dispaly outputs of machine1
       System.out.println(\"Machine 2 Votes\\t boor\"+vs.boor2+\",\\t crocky \"+vs.crocky2 +\",\\t hugger \"+vs.hugger2+\"\ \");           //dispaly outputs of machine2


   }
      
}
class VotingSystem                                                   //class for voting data to hold
{
   public static int boor1,crocky1,hugger1;                   //varible declarations
   public static int boor2,crocky2,hugger2;

public static void savevote(int m1,int cand)                   //function defination to save voting data
   {
       if(m1==1)                                               //if machine1 store votes in varibles
           if(cand==1)
           boor1=boor1+1;
           if(cand==2)
           crocky1=crocky1+1;
           if(cand==3)
               hugger1=hugger1+1;
       else                                                                           //if machine2 store votes in varibles
           if(cand==1)
           boor2=boor2+1;
       if(cand==2)
           crocky2=crocky2+1;
           if(cand==3)
               hugger2=hugger2+1;
   }
}

Output :


Comile : javac vote.java

Run : java vote

Sample Output 1:
Do you Wish to Vote(1),End of Programme(0)
1
Do you Wish to use Machine(1) or Machine(2)
1
Do you Wish to vote Boor(1) or Crocky(2) or hugger[3]
1
Do you Wish to Vote(1),End of Programme(0)
1
Do you Wish to use Machine(1) or Machine(2)
2
Do you Wish to vote Boor(1) or Crocky(2) or hugger[3]
2
Do you Wish to Vote(1),End of Programme(0)
1
Do you Wish to use Machine(1) or Machine(2)
2
Do you Wish to vote Boor(1) or Crocky(2) or hugger[3]
2
Do you Wish to Vote(1),End of Programme(0)
0
Machine 1 Votes boor1, crocky 2, hugger0

Machine 2 Votes boor0, crocky 2, hugger 0

ElectionCentral.java Can you please help me the JAVA program? The people of the town of Dante are voting today, and they need a voting system. Your mission is t
ElectionCentral.java Can you please help me the JAVA program? The people of the town of Dante are voting today, and they need a voting system. Your mission is t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site