Question: hi, in java im supposed to create a program that tallys votes for two candidates for office: Tichen and Orator. If 1 is entered then

hi, in java im supposed to create a program that tallys votes for two candidates for office: Tichen and Orator. If 1 is entered then they voted for Tichen, if 2 then voted for Orator, if -1 then there arent any more voters, while other inputs are treated as errors. Then after the vote reading, it should display the total number of votes received, total number of votes for each candidate, the percent of votes each candidate got, and a message to say who wins of if its a tie. So far this is what I have:

import java.util.Scanner; public class PaulAssignment

{ public static void main (String args[]) { Scanner scan = new Scanner (System.in); int userData = scan.nextInt(); int Tichen = 0; int Orator = 0; int total = Tichen + Orator; while(userData == 1 | userData == 2) { System.out.println("Enter your vote "); userData = scan.nextInt(); scan.nextLine(); if(userData == 1) { Tichen++; } if(userData == 2) { Orator++; } else { System.out.println("Unrecognized input!! Please enter 1 or 2"); } if (Tichen != Orator) { System.out.println("Tichen: " +Tichen); System.out.println("Orator: " +Orator); System.out.println("Total number of votes: " +total); } else { System.out.println("Tichen: " +Tichen); System.out.println("Orator: " +Orator); System.out.println("It is a tie"); } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!