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 1: 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 Contestant(String name, int age){ super(name, age); this.positionHistory = new ArrayList<>(); } public void recordPosition(int position){ positionHistory.add(position); } public double getAveragePosition(){ if (positionHistory.isEmpty()) return 0; int sum =0; 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 2: 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 main(String[] args){ int numContestants =8; // Start with a small number int numRounds =12; // Medium number of rounds ArrayList contestants = new ArrayList<>(); // Create contestants for (int i =0; i < numContestants; i++){ Contestant contestant = new Contestant("Contestant"+ i,20+ i); contestants.add(contestant); }// Simulate rounds Random random = new Random(); for (int round =0; round < numRounds; round++){ ArrayList newOrder = new ArrayList<>(); for (Contestant contestant : contestants){ boolean correctAnswer = random.nextBoolean(); if (correctAnswer){ newOrder.add(0, contestant); // Move to front } else { newOrder.add(contestant); // Move to back }} contestants = newOrder; // Record positions for (int i =0; i < contestants

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!