Package becker.xtras.gasPump

The gasPump package provides a graphical user interface (GUI) for a gas pump that uses three instances of a student-written class implementing the IMeter interface.

See:
          Description

Interface Summary
IMeter Objects implementing IMeter are used to measure the volume of fuel delivered to a customer at a gas pump.
 

Class Summary
GasPumpGUI A graphical user interface to simulate a gas pump.
SampleMeter A sample class implementing the IMeter interface.
 

Package becker.xtras.gasPump Description

The gasPump package provides a graphical user interface (GUI) for a gas pump that uses three instances of a student-written class implementing the IMeter interface. The GUI appears like this:

A typical main method to run this program would be

import becker.xtras.gasPump.*;

public class Main
{
   public static void main(String[] args)
   {  
      IMeter silver = new SampleMeter(1.10, 87, "Silver");
      IMeter gold = new SampleMeter(1.149, 89, "Gold");
      IMeter platinum = new SampleMeter(1.199, 93, "Platinum");
        
      GasPumpGUI gui = new GasPumpGUI(silver, gold, platinum, "Liter");
   }
}

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

This program uses the Model-View-Controller pattern. The class implementing IMeter 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 Meter implements IMeter
{
   private ViewList views = new ViewList();

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