Java Reference
In-Depth Information
Lab 10.1: Implementing an Interface
In this lab, you will write your own version of a FootballListener and use
the FootballGame class from this chapter to add your FootballListener to
the audience.
1. Start by copying the FootballGame.class and FootballListener.class
files into a new directory you create, named c:\football.
2. Declare a class named CellPhone that implements FootballListener.
3. Within your CellPhone class, add fields for the names of the teams,
their scores, and the current quarter.
4. Add all of the methods in the FootballListener interface. The
assumption here is that a CellPhone display has limited resources,
so only display an output (to System.out) when the score changes or
when the game is over. Try to limit the text of your output as much
as possible, while still displaying the information in an informative
manner.
5. Save the CellPhone class in your c:\football directory and then com-
pile it.
6. Write a program that simulates a football game. You will need to
instantiate a FootballGame object and a CellPhone object, and
invoke addFootballListener(), passing in your CellPhone object.
7.
Simulate a game by having the two teams score and the quarters
change; then run your program to verify that your CellPhone object
is listening and displaying the proper results of the game.
As the football game is played, you should be able to watch it on the
CellPhone, seeing the output at the command prompt.
Lab 10.2 Interfaces and javadoc
This lab demonstrates how the javadoc tool creates documentation for
interfaces.
1.
In Lab 10.1, you created a directory named c:\football. Make sure
that directory has the following four .class files in it: FootballGame,
FootballListener, CellPhone, and your program that simulates a
football game.
Search WWH ::




Custom Search