Answered step by step
Verified Expert Solution
Question
1 Approved Answer
coding java help please urgent Problem #2: (20 pts] _Voting Program Two candidates are running for president of a service organization. The winner is the
coding java help please urgent
Problem #2: (20 pts] _Voting Program Two candidates are running for president of a service organization. The winner is the candidate with the most votes. Write a Java program that asks the user to enter the number of voters in the organization and the number of votes for each candidate. Your program displays which candidate wins and if he/she wins by majority. If one candidate has more than 50% of the votes, then he/she wins by majority. NB: If any of the integers is negative, then the program displays the message Invalid number(s)! In case of draw, the message "It is a draw, select a candidate at random is displayed. Sample run 1: Enter the number of voters: 40 Enter number of votes for candidate 1: 15 Enter number of votes for candidate 2: 12 Candidate 1 wins. He/she didn't win by majority, because the percentage is 37.5% Hint: Candidate 1 didn't win by majority because only 15 voters out of 40 voted in his favor. Sample run 2: Enter the number of voters: 40 Enter number of votes for candidate 1: -15 Enter number of votes for candidate 2: 12 Invalid number(s)! Sample run 3: Enter the number of voters: 20 Enter number of votes for candidate 1: 10 Enter number of votes for candidate 2: 11 Candidate 2 wins. He/she wins by majority, because the percentage is 55.0% Hint: Candidate 2 wins by majority because 11 voters out of 20 voted in his favor. Sample run 4: Enter the number of voters: 20 Enter number of votes for candidate 1: 10 Enter number of votes for candidate 2: 10 It is a draw, select a candidate at random
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started