Question
Please code in Java and if you can do extra credit portion it would be appreciated. Election Student Government recently had elections for the new
Please code in Java and if you can do extra credit portion it would be appreciated.
Election
Student Government recently had elections for the new President for the 2017-2018 school year. You must write a program that allows the user to enter the candidates names and number of votes receives, calculates the total number of votes cast and the percentage of votes received by each candidate, and displays the candidates names, the number of votes received, and thepercentage of votes received.
Your program should prompt the user (customer) to enter the following information:
Candidates names
Number of votes received by each candidate
The program then outputs the following information:
Candidates names
Number of votes received by each candidate
Percentage of votes received by each candidate
Total number of votes cast
Please refer to the Sample Output file for full details of what the program should look like when it runs.
Program requirements:
Your program MUST read all of the information about the candidates (names and votes received) BEFORE doing anything else in the program (e.g. calculating the total number of votes cast)
You MUST store the following information in three different arrays: candidates names;number of votes received by each candidate; percentage of votes received by each candidate.
Your program MUST include the following user-defined method, in addition to the mainmethod: Calculate total number of votes cast in the election.
This method processes the array of votes received and returns the total number of votes
cast (HINT: Pass the array as a parameter to this method)
Possible high-level outline for the logic of your program (you do NOT have to follow these steps this is just a suggestion):
Loop to read the name of each candidate into an array and the number of votes received into an array
Call method to calculate the total number of votes cast Loop to calculate the percentage of votes earned by each candidate Loop to print the candidates names, number of votes received, and percentage of votes received Print total votes cast
1
NOTE: If your program sometimes skips the step where the user can enter the name of thecandidate, use next() (not nextLine()). None of the candidates names will have spaces, sonextLine() is not needed.
2
This assignment MUST be created individually. You must turn in your OWN source code and Java bytecode executable file. You MAY NOT share files!
Instructions
Compile and execute your program to ensure that it works correctly.
Be sure to run your final program using the sample data included in the Sample Output file
to ensure your program works properly.
Make sure your output labels match those in the Sample Output file exactly.
Notes
You MUST store any calculations in variables.
You do NOT need to worry about formatting the decimal places on values you calculate
You may perform the tasks in any order as long as your output follows the order of the
output in the example scenarios contained in the Sample Output file
You must include the one user-defined method specified above. You may include additional
methods if you want, but you MUST include at least this method in addition to main.
Do NOT use global variables unless you have a REALLY good reason for doing so.
Extra credit (10 points)
Determine the winner of the election, and print the winner to the screen. Please refer to the Sample Output BONUS file for formatting details. You do not need special syntax to do this you will have to think logically about how to solve this problem.
To receive full credit:
Submit the following files in a single zip file to Canvas
o File with your Java source code (.java file) o File with your Java bytecode executable file (.class file) o Refer to the instructions for creating the zip file on Canvas if you do not create
the file with the correct folders and structure, you will lose points
ModulesNetBeans Information -> NetBeans -> where are my files for my hw?
You must follow the appropriate Coding Standards listed in the Coding Standards document
under Modules on Canvas. o 40% of your grade on the source code will be based on how well you follow these
standards and how well you comment your source code
SAMPLE PROGRAM OUTPUT
Be sure to format the output of your program so that it follows what is included in the example below. Remember, bold items are entered by the user when the program runs (and therefore can change each time the program runs).
Please enter the candidate's name: DoryPlease enter the number of votes: 5000
Please enter the candidate's name: NemoPlease enter the number of votes: 4000
Please enter the candidate's name: DestinyPlease enter the number of votes: 6000
Please enter the candidate's name: BaileyPlease enter the number of votes: 2500
Please enter the candidate's name: MarlinPlease enter the number of votes: 1800
Candidate Dory Nemo Destiny Bailey Marlin Total
Votes Percentage 5000 25.906735751295336% 4000 20.72538860103627% 6000 31.088082901554404% 2500 12.953367875647668% 1800 9.32642487046632% 19300 BONUS SAMPLE PROGRAM OUTPUT
Be sure to format the output of your program so that it follows what is included in the example below. Remember, bold items are entered by the user when the program runs (and therefore can change each time the program runs).
Please enter the candidate's name: DoryPlease enter the number of votes: 5000
Please enter the candidate's name: NemoPlease enter the number of votes: 4000
Please enter the candidate's name: DestinyPlease enter the number of votes: 6000
Please enter the candidate's name: BaileyPlease enter the number of votes: 2500
Please enter the candidate's name: MarlinPlease enter the number of votes: 1800
Candidate Dory Nemo Destiny Bailey Marlin Total
Votes Percentage 5000 25.906735751295336% 4000 20.72538860103627% 6000 31.088082901554404% 2500 12.953367875647668% 1800 9.32642487046632% 19300
The next Student Government President is Destiny.
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