Question: To implement the Contestant class and the simulation as described, follow these steps: Step 1 : Implement the Contestant Class First, extend the Person class
To implement the Contestant class and the simulation as described, follow these steps:
Step : Implement the Contestant Class
First, extend the Person class to create the Contestant class. Add attributes to track the contestant's position history and methods to calculate the average position.
public class Contestant extends Person private ArrayList positionHistory; public ContestantString name, int age supername age; this.positionHistory new ArrayList; public void recordPositionint position positionHistory.addposition; public double getAveragePosition if positionHistoryisEmpty return ; int sum ; for int pos : positionHistory sum pos; return double sum positionHistory.size; @Override public String toString return "Contestant Name getName Age getAge Average Position getAveragePosition;
Step : Implement the Contest Simulation
Modify the ContestDriver class to simulate the contest rounds.
import java.util.ArrayList; import java.util.Random; public class ContestDriver public static void mainString args int numContestants ; Start with a small number int numRounds ; Medium number of rounds ArrayList contestants new ArrayList; Create contestants for int i ; i numContestants; i Contestant contestant new ContestantContestant i i; contestants.addcontestant; Simulate rounds Random random new Random; for int round ; round numRounds; round ArrayList newOrder new ArrayList; for Contestant contestant : contestants boolean correctAnswer random.nextBoolean; if correctAnswer newOrder.add contestant; Move to front else newOrder.addcontestant; Move to back contestants newOrder; Record positions for int i ; i contestants
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
