Having trouble adding to ArrayList. I have to convert the normal array to an arraylist.
16.01 Assignment Instructions
Instructions: For this assignment, you are going to use traversal methods.
1. Create a folder called 16.01 Assignment in your module 16 assignments folder.
2. Create a class called Candidate.
a. Candidate will need instance variables name and numVotes (of types String
and int, respectively).
b. Candidate will need appropriate methods and constructors. Make sure to have a
toString() method that prints the name of the Candidate along with the
number of votes.
c. Save the class as Candidate.java.
3. Create a class called TestCandidate and save it as TestCandidate.java.
a. Make sure that you create an array called election. Add the following
Candidates with their votes:
Candidate Vote
John Smith 5000
Mary Miller 4000
Michael Duffy 6000
Tim Robinson 2500
Joe Ashtony 1800
b. Create a method called printVotes() that traverses through the array and
prints out each element.
c. Create a method called getTotal() that traverses through the array and counts
the total of the votes for all Candidates. It should return that number.
d. Create a method called printResults() that traverses through the array and
creates a table with columns for Candidate name, followed by votes received, and
then percentage of total votes (you can round these values). Note that this method
will need to call getTotal() to use in constructing the third column. After
printing the table, print a line showing the total number of votes for all
Candidates.
e. Test your methods. Your output should be similar to that shown below: 4. Now create a class TestCandidate2 and save it as TestCandidate2.java.
a. Create the same items as for TestCandidate; however, use an ArrayList
instead.
b. Output should still look the same as for TestCandidate.
I have done all of this fine. Just the last step is giving me trouble.
Here is my code.
Any help would be great...