Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

Describe ERP and how it can create efficiency within a business

Answered: 1 week ago