Candidate Class Homework

Activity, Due April 23

Start with: https://repl.it/@JimSkon/Candidate

Make and turn in a new repl.it for each. Turn in a run of each.

Moodle.

Step 1:
  1. Test the function to change the polls for each candidate
  2. Add 2 new candidates of your choice.
  3. Display the candidates
  4. Modify the class to also store and display the candidates age. Write code to test it.
  5. Create a method birthday() that increases the candidates age by one. Write code to test it.
Step 2:
  1. Create an empty list of candidate
  2. Make a loop that asks for a candidate name, part, and poll, and creates a candidate an append to the array.
  3. Loop until user is done
  4. Loop and print out all of the candidates in the list.
Step 3.
  1. Fork the project to make a new version that stores polls in a list of polls rather then as a single poll number.
  2. Change the polls to be an array of integers rather than a single integer.
  3. Modify the constructor to only accept a name and party. It should then create a candidate with an empty poll list.
  4. Add a method addPoll(num) to append a poll to that candidate's poll list.
  5. Modify display() to only print out the latest (last) poll in the list for the candidate (Along with the name and party as before).
  6. Add method showPolls() to show the name of the candidate, all the polls for that candidate, and the average of those polls. Make the output nicely formatted so the viewer knows what they are seeing.
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2019-03-18 - JimSkon
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback