Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a set of Java classes to simulate a line of Contestants. You are given the class Person, and you will write a Contestant class,
Write a set of Java classes to simulate a line of Contestants.
You are given the class Person, and you will write a Contestant class, where Contestant extends Person. Start simple to make sure your code compiles and runs. As you progress through the lab, you will need to add attributes and methods to the Contestant class to complete the assignment.
Create n Contestants, each with a different name, and add them all to an ArrayList of Contestants. n can be any value between and though I suggest you start small with a value like Later, you will increase the size of n so plan for this now.
Figure out how to flip a coin. You want to generate a boolean that is True about of the time and False about of the time, over a large number of coin flips. See java.util.Random or java.util.concurrent.ThreadlocalRandom if you need a place to get started.
In a real contest, each Contestant in turn is asked a question, and moves to a new spot in the line depending on whether the answer is correct or not. One simple algorithm is to move to the front of the line on a correct answer, and the back of the line on an incorrect answer. So suppose there is a line of Contestants abcde where a and d get an answer wrong, and b c and e get their answers correct.
a b c d e
Initial position
b c d e a
a answers incorrectly and moves to the end
b c d e a
b answers correctly and moves to the front
c b d e a
c answers correctly and moves to the front
c b e a d
d answers incorrectly and moves to the end
e c b a d
e answers correctly and moves to the front
This represents one round of the competition. At the end of the round, e is at position c is at position and d is at position Implement one round using this algorithm. Use your coin flip to determine whether an answer was correct or not. Write a paragraph explaining how you tested your code to know it works correctly. Include this in your final writeup
Modify your program to run a series of rounds. Each round should process the Contestants starting from position But first, modify the Contestant class so that it can record a Contestant's position in the list and calculate the Contestant's average position. You will have to figure out how to store this data in each Contestant and what calculation to make, and what methods to provide. In the driver program, you should record each Contestant's position at the end of each round. Run your program with a small number of Contestants and a medium number of rounds Use the average position of each contestant to show that this algorithm isn't biased against certain Contestants, that is no Contestant gets stuck at one end of the line or the other for most of the game. Write a paragraph or two with an explanation of how you tested this and show your data.
Add code to calculate the time it takes to run your simulation in step Do not include the time to calculate the fairness aspect. Change the number of Contestants to and then run your program more times for and rounds. Record the number of rounds and run times in a table.
Increase the number of Contestants to then repeat step Add this data to your table and include it in your report.
The folks running the game dont like the optics of moving people to the front or end of the line each time. Think about a different algorithm for moving people around in the list. You can't decrease the size of the list and the list will get rearranged in some way during each round. Write a paragraph or two on what would have to change in your program to implement the new algorithm, still using an ArrayList. Be as specific as you can with regard to your code. Consider whether it would be easy or hard to implement and estimate whether it will take more or less time to run than the current implementation. Be sure to explain your reasons.
Notes
You need to specify a message every time you commit your code to a repository. Like comments in the program, these should be meaningful. Saying "Added files" isn't going to tell you anything when you look back. Saying something like "Step completed" is better, but after a week, you won't remember what step was. A better comment would be "Step completed method to flip a coin".
In writing your classes, remember that instance variables should be private to the class.
Your code should also contain meaningful comments. At a minimum, each file requires a descriptive header comment with your name, date, and the purpose of the code. Methods that do more than just accessmodify an instance variable should have a header comment describing the input parameters, the return value if any and what the method does.
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