Election Central Can you please help me the JAVA program The

Election Central

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(O)? 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(O)? 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(O)? 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 three classes. One class should contain a main method and manage the dialog with the user. Another class should represent a voting machine. The third should represent a candidate and his votes. The design of the voting machine class is up to you. Make sure that your instance variables are private, follow the naming conventions, etc. In other words, don\'t create one object for candidate \"sophie\" and add it to both machines; create two \"sophie\" candidates and add one to one machine, and the other to the other machine.

Solution

Driver.java

package snippet;

import java.util.Scanner;

public class Driver {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       boolean flag=true;
      
       Candidate[] c1=new Candidate[3];//create array of candidate for macine 1
       c1[0]=new Candidate();
       c1[1]=new Candidate();
       c1[2]=new Candidate();
      
      
       //Set details and vote count
       c1[0].setCandidate(\"boor\",0);
       c1[1].setCandidate(\"crook\",0);
       c1[2].setCandidate(\"tree hugger\",0);
      
      
       Candidate[] c2=new Candidate[3];//create array of candidate for macine 2
       c2[0]=new Candidate();
       c2[1]=new Candidate();
       c2[2]=new Candidate();
      
      
       //Set details and vote count
       c2[0].setCandidate(\"boor\",0);
       c2[1].setCandidate(\"crook\",0);
       c2[2].setCandidate(\"tree hugger\",0);
      
       VotingMachine m1=new VotingMachine(c1);//Set Candidate to machine 1
      
       VotingMachine m2=new VotingMachine(c2);//Set Candidate to machine 2
      
       while(flag)
       {
          
      
       System.out.println(\"Do you want to vote(1),or end the program(0) \");
      
       int ch;
       Scanner sc=new Scanner(System.in);
      
       ch=sc.nextInt();
      
       if(ch==1)
       {
           System.out.println(\"Do you want to Machine(1)or Machine(2) \");
           ch=sc.nextInt();
          
           if(ch==1)
           {
               System.out.println(\"1Do you want to vote for boor(1),crook(2),tree hugger(3) \");
               ch=sc.nextInt();
              
               if(ch==1)
               {
                   m1.increaseVote(c1,0);//increase votes of boor
                  
               }
              
               if(ch==2)
               {
                   m1.increaseVote(c1,1);//increase votes of crook
               }
              
               if(ch==3)
               {
                   m1.increaseVote(c1,2);//increase votes of tree hugger
               }
              
              
              
           }
          
           if(ch==2)
           {
               System.out.println(\"2Do you want to vote for boor(1),crook(2),tree hugger(3) \");
               ch=sc.nextInt();
              
               if(ch==1)
               {
                   m2.increaseVote(c2,0);//increase votes of boor
                  
               }
              
               if(ch==2)
               {
                   m2.increaseVote(c2,1);//increase votes of crook

               }
              
               if(ch==3)
               {
                   m2.increaseVote(c2,2);//increase votes of tree hugger
               }
           }

       }
       else
       {
           flag=false;
       }
      
      
      
      
          
       }
       System.out.println(\"Machine 1 Votes: boor \"+m1.getCount(c1[0])+\" crook \"+m1.getCount(c1[1])+\" tree hugger\"+m1.getCount(c1[2]) );
       System.out.println(\"Machine 2 Votes: boor \"+m2.getCount(c2[0])+\" crook \"+m2.getCount(c2[1])+\" tree hugger\"+m2.getCount(c2[2]) );
      
      

   }

}

================================================================

VotingMachine.java

package snippet;

public class VotingMachine {
   private Candidate c[];
  
  
   public VotingMachine(Candidate[] obj)
   {
       // TODO Auto-generated constructor stub
       c=obj;
              
      
   }
  
   public void increaseVote(Candidate[] c1,int num)
   {
       c1[num].increaseCandidateVote();
   }
  
   public int getCount(Candidate c1)
   {
      
       return c1.getCandidateVote();
      
   }

}

=========================================================

Candidate.java

package snippet;

public class Candidate {
   private String name;
   private int voteCount;
  
   public Candidate() {
       // TODO Auto-generated constructor stub
       name=\"\";
       voteCount=0;
   }
  
   public Candidate(String n,int v)
   {
       // TODO Auto-generated constructor stub
       name=n;
       voteCount=v;
   }

  
   public void setCandidate(String n,int v)
   {
       // TODO Auto-generated constructor stub
       name=n;
       voteCount=v;
   }
  
   public void increaseCandidateVote()
   {
       // TODO Auto-generated constructor stub
       voteCount++;
      
   }
  
   public int getCandidateVote()
   {
       // TODO Auto-generated constructor stub
       return voteCount;
      
   }
}

===========================================================

========================================================

Output:

Do you want to vote(1),or end the program(0)
1
Do you want to Machine(1)or Machine(2)
2
2Do you want to vote for boor(1),crook(2),tree hugger(3)
2
Do you want to vote(1),or end the program(0)
1
Do you want to Machine(1)or Machine(2)
1
1Do you want to vote for boor(1),crook(2),tree hugger(3)
3
Do you want to vote(1),or end the program(0)
0
Machine 1 Votes: boor 0 crook 0 tree hugger1
Machine 2 Votes: boor 0 crook 1 tree hugger0

Election Central 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 cr
Election Central 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 cr
Election Central 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 cr
Election Central 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 cr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site