Question: package medleySimulation; public class FinishCounter { private boolean firstAcrossLine; / / flag private int winner; / / who won private int winningTeam; / / counter
package medleySimulation;
public class FinishCounter
private boolean firstAcrossLine; flag
private int winner; who won
private int winningTeam; counter for patrons who have left the club
FinishCounter
firstAcrossLine true;noone has won at start
winner; noone has won at start
winningTeam; noone has won at start
This is called by a swimmer when they touch the fnish line
public synchronized void finishRaceint swimmer, int team
boolean won false;
iffirstAcrossLine
firstAcrossLinefalse;
won true;
if won
winnerswimmer;
winningTeamteam;
Has race been won?
public boolean isRaceWon
return firstAcrossLine;
public int getWinner return winner;
public int getWinningTeam return winningTeam;
package medleySimulation;
import medleySimulation.Swimmer.SwimStroke;
public class SwimTeam extends Thread
public static StadiumGrid stadium; shared
private Swimmer swimmers;
private int teamNo; team number
public static final int sizeOfTeam;
SwimTeam int ID FinishCounter finish,PeopleLocation locArr
this.teamNoID;
swimmers new SwimmersizeOfTeam;
SwimStroke strokes SwimStroke.values; Get all enum constants
stadium.returnStartingBlockID;
forint iteamNosizeOfTeams;iteamNosizeOfTeam; isinitialise swimmers in team
locArri new PeopleLocationistrokessgetColour;
int speedintMathrandom; range of speeds
swimmerss new SwimmeriteamNo,locArrifinish,speed,strokess; hardcoded speed for now
public void run
try
forint s;s return false; space is occupied
isOccupied threadID; set ID to thread that had block
return true;
release a block
public void release
isOccupied;
is a bloc already occupied?
public boolean occupied
ifisOccupied return false;
return true;
is a start block
public boolean isStart
return isStart;
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
