Question: d) Design and implement a test class. This should contain a main method to do the following (23 marks): 1. Write a method that randomly




d) Design and implement a test class. This should contain a main method to do the following (23 marks): 1. Write a method that randomly generates an odd number of votes in the range 1-10. (3 marks) 2. Write a recursive method that fills and returns a list of random votes for either Trump or Biden of length n where n is an odd number. (Call your method in d(1) to get an odd number to be sent as parameter to the recursive fill method). (6 marks) 3. Create a list of candidates that consists of the two candidates; Trump and Biden for 2020 US presidential election. (2.5 marks) 4. Create a list of US states. Fill in the list of states with hard- coded test data (no user input) from the table above. The states list should hold at least five state objects of any type (WTA and CDP states) where at least one of states is a CDP state. Call your method in d(2) to get a randomly generated votes list for each state or CD. (5 marks) 5. For each state, display the candidate list and the state certified winner. At end, announce the overall Us Presidential Election Results 2020 for each candidate and the certified winner. (6.5 marks) Total Electoral Votes: 538; Majority Needed to Elect: 270 Electoral votes Electoral vates 3 18 7 7 20 State Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware District of Columbia Florida Georgia Hawaii Idaho Illinois Indiana lowa Kansas Electoral votes 9 3 11 6 55 9 7 3 3 29 16 4 4 20 11 6 6 State Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina State North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming 4. 10 11 16 10 6 10 3 5 6 4 14 5 29 15 9 3 11 6 3 13 12 5 10 3 Sample run which takes from table 1, the first four states in addition to Nebraska. The state's output was generated from randomly generated vates list: Electoral votes Alabama Candidate Trump Candidate Biden Winner: Candidate Trump: Popular votes 4 Popular votes 3 Electoral votes 0 Popular votes Electoral votes Alaska Candidate Trump Candidate Biden Winner: Candidate Biden Popular votes 1 Popular votes 4 Electoral votes 0 Electoral votes 3 Popular votes 4 Electoral votes 3 Electoral votes Arizona Candidate Trump Candidate siden Winner: Popular votes 2 Popular votes 3 Electoral votes 11 Candidate Biden: Popular votes Electoral votes 3 11 Arkansas Candidate Trump Candidate Biden: Winner: Candidate Trump Popular votes Electoral votes 6 Popular votes Electoral votes 3 Popular votes Electoral votes 10 Nebraska Candidate Trump: Candidate Biden: Winner: Candidate Biden Popular votes Electoral votes 1 Popular votes Electoral votes 15 Popular votes Electoral votes 15 23 US Presidential Election Results 2020: Candidate Popular votes Electoral votes Trump: 16 Candidate Popular votes Electoral votes Biden 28 18 Winner: Candidate Popular votes Electoral votes Biden 28 18 d) Design and implement a test class. This should contain a main method to do the following (23 marks): 1. Write a method that randomly generates an odd number of votes in the range 1-10. (3 marks) 2. Write a recursive method that fills and returns a list of random votes for either Trump or Biden of length n where n is an odd number. (Call your method in d(1) to get an odd number to be sent as parameter to the recursive fill method). (6 marks) 3. Create a list of candidates that consists of the two candidates; Trump and Biden for 2020 US presidential election. (2.5 marks) 4. Create a list of US states. Fill in the list of states with hard- coded test data (no user input) from the table above. The states list should hold at least five state objects of any type (WTA and CDP states) where at least one of states is a CDP state. Call your method in d(2) to get a randomly generated votes list for each state or CD. (5 marks) 5. For each state, display the candidate list and the state certified winner. At end, announce the overall Us Presidential Election Results 2020 for each candidate and the certified winner. (6.5 marks) Total Electoral Votes: 538; Majority Needed to Elect: 270 Electoral votes Electoral vates 3 18 7 7 20 State Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware District of Columbia Florida Georgia Hawaii Idaho Illinois Indiana lowa Kansas Electoral votes 9 3 11 6 55 9 7 3 3 29 16 4 4 20 11 6 6 State Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina State North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming 4. 10 11 16 10 6 10 3 5 6 4 14 5 29 15 9 3 11 6 3 13 12 5 10 3 Sample run which takes from table 1, the first four states in addition to Nebraska. The state's output was generated from randomly generated vates list: Electoral votes Alabama Candidate Trump Candidate Biden Winner: Candidate Trump: Popular votes 4 Popular votes 3 Electoral votes 0 Popular votes Electoral votes Alaska Candidate Trump Candidate Biden Winner: Candidate Biden Popular votes 1 Popular votes 4 Electoral votes 0 Electoral votes 3 Popular votes 4 Electoral votes 3 Electoral votes Arizona Candidate Trump Candidate siden Winner: Popular votes 2 Popular votes 3 Electoral votes 11 Candidate Biden: Popular votes Electoral votes 3 11 Arkansas Candidate Trump Candidate Biden: Winner: Candidate Trump Popular votes Electoral votes 6 Popular votes Electoral votes 3 Popular votes Electoral votes 10 Nebraska Candidate Trump: Candidate Biden: Winner: Candidate Biden Popular votes Electoral votes 1 Popular votes Electoral votes 15 Popular votes Electoral votes 15 23 US Presidential Election Results 2020: Candidate Popular votes Electoral votes Trump: 16 Candidate Popular votes Electoral votes Biden 28 18 Winner: Candidate Popular votes Electoral votes Biden 28 18
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
