Java Reference
In-Depth Information
}
else
{
System.out.println(“Final score”);
}
}
public void homeTeamScored(int points)
{
System.out.println(“The home team just scored “ + points);
homePoints += points;
updateScore();
}
public void visitingTeamScored(int points)
{
System.out.println(“The visiting team just scored “ + points);
visitorPoints += points;
updateScore();
}
public void endOfQuarter(int quarter)
{
if(quarter >= 1 && quarter <= 3)
{
currentQuarter++;
}
else
{
currentQuarter = -1; //game is over
}
System.out.println(“Quarter “ + quarter + “ just ended.”);
updateScore();
}
public void setHomeTeam(String name)
{
home = name;
}
public void setVisitingTeam(String name)
{
visitors = name;
}
}
The ScoreBoard class contains an implementation for each method in Foot-
ballListener, and therefore successfully implements the FootballListener inter-
face. The following OaklandAtDenver program demonstrates a ScoreBoard
object adding itself to the audience Vector of a FootballGame object. Whenever
an event occurs in the DenverAtOakland game, the ScoreBoard object is
notified.
Study the OaklandAtDenver program and try to determine its output. Run
the program to verify the output.
Search WWH ::




Custom Search