Package becker.xtras.tollBooth

The tollBooth package provides a graphical user interface (GUI) for a highway toll booth simulation that uses an instance of a student-written class implementing the ITollBooth interface.

See:
          Description

Interface Summary
ITollBooth Objects implementing ITollBooth are used to collect tolls from passing vehicles on a highway.
 

Class Summary
SampleTollBooth A sample class implementing the ITollBooth interface.
TollBoothGUI A graphical user interface to simulate a highway toll booth.
 

Package becker.xtras.tollBooth Description

The tollBooth package provides a graphical user interface (GUI) for a highway toll booth simulation that uses an instance of a student-written class implementing the ITollBooth interface. The GUI appears like this:

A typical main method to run this program would be

import becker.xtras.tollBooth.*;

public class Main
{
   public static void main(String[] args)
   {  TollBooth booth = new TollBooth();
          TollBoothGUI gui = new TollBoothGUI(booth);
   }
}

where TollBooth is written by the student and implements the ITollBooth interface. The library includes an implementation of ITollBooth named SampleTollBooth. Substituting it for TollBooth in the above code will yield a working demonstration program.

This program uses the Model-View-Controller pattern. The class implementing ITollBooth is the model. It must arrange to update the views each time the model's state (that is, one of its instance variables) changes. This can be done easily with code such as the following:

import becker.util.IView;
import becker.util.ViewList;

public class TollBooth implements ITollBooth
{
   private ViewList views = new ViewList();

   ...
   
   public void stateChangingMethod()
   {  ...
      this.views.updateViews();
   }
   
   public void addView(IView aView)
   {  this.views.addView(aView);
   }
}