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;//no-one has won at start
winner=-1; //no-one has won at start
winningTeam=-1; //no-one has won at start
}
//This is called by a swimmer when they touch the fnish line
public synchronized void finishRace(int swimmer, int team){
boolean won =false;
if(firstAcrossLine){
firstAcrossLine=false;
won = true;
}
if (won){
winner=swimmer;
winningTeam=team;
}
}
//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=4;
SwimTeam( int ID, FinishCounter finish,PeopleLocation [] locArr ){
this.teamNo=ID;
swimmers= new Swimmer[sizeOfTeam];
SwimStroke[] strokes = SwimStroke.values(); // Get all enum constants
stadium.returnStartingBlock(ID);
for(int i=teamNo*sizeOfTeam,s=0;i<((teamNo+1)*sizeOfTeam); i++,s++){//initialise swimmers in team
locArr[i]= new PeopleLocation(i,strokes[s].getColour());
int speed=(int)(Math.random()*(3)+30); //range of speeds
swimmers[s]= new Swimmer(i,teamNo,locArr[i],finish,speed,strokes[s]); //hardcoded speed for now
}
}
public void run(){
try {
for(int s=0;s=0) return false; //space is occupied
isOccupied= threadID; //set ID to thread that had block
return true;
}
//release a block
public void release(){
isOccupied=-1;
}
//is a bloc already occupied?
public boolean occupied(){
if(isOccupied==-1) 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 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!