becker.xtras.gasPump
Class SampleMeter

java.lang.Object
  extended by becker.xtras.gasPump.SampleMeter
All Implemented Interfaces:
IMeter

public final class SampleMeter
extends Object
implements IMeter

A sample class implementing the IMeter interface. It measures the volume of fuel sold and calculates the amount owed by the customer, given the current fuel cost.

Please see the package description for a more in-depth discussion of using this class.

Author:
Byron Weber Becker

Constructor Summary
SampleMeter(double unitCost, int octaneRating, String theLabel)
          Construct a new fuel meter.
 
Method Summary
 void addView(IView aView)
          Add a view (graphical user interface) to the meter.
 double calcTotalCost()
          Calculate the total cost of fuel sold to this customer.
 String getLabel()
          Get the label for this meter's fuel.
 int getOctane()
          Get the octane rating of the fuel.
 double getUnitCost()
          Get the cost per unit of fuel.
 double getVolumeSold()
          Get the volume of fuel sold to this customer.
static void main(String[] args)
          Used to test the class.
 void pump(double howMuch)
          Pump some fuel into a tank.
 void reset()
          Reset the meter for a new customer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampleMeter

public SampleMeter(double unitCost,
                   int octaneRating,
                   String theLabel)
Construct a new fuel meter.

Parameters:
unitCost - The cost per unit volume of fuel. For example, $2.85/gallon or $1.05/litre.
octaneRating - An integer related to the "performance" of the fuel; usually between 87 and 93.
theLabel - A label for the fuel such as "Gold" or "Ultra".
Method Detail

reset

public void reset()
Description copied from interface: IMeter
Reset the meter for a new customer.

Specified by:
reset in interface IMeter

pump

public void pump(double howMuch)
Description copied from interface: IMeter
Pump some fuel into a tank. This method is called repeatedly while the "handle" on the pump is pressed.

Specified by:
pump in interface IMeter
Parameters:
howMuch - How much fuel was pumped since the last time this method was called.

getUnitCost

public double getUnitCost()
Description copied from interface: IMeter
Get the cost per unit of fuel.

Specified by:
getUnitCost in interface IMeter
Returns:
cost per unit of fuel

getVolumeSold

public double getVolumeSold()
Description copied from interface: IMeter
Get the volume of fuel sold to this customer.

Specified by:
getVolumeSold in interface IMeter
Returns:
volume of fuel sold

getOctane

public int getOctane()
Description copied from interface: IMeter
Get the octane rating of the fuel.

Specified by:
getOctane in interface IMeter
Returns:
octane rating (typically between 87 and 93)

getLabel

public String getLabel()
Description copied from interface: IMeter
Get the label for this meter's fuel. For example, "Gold" or "Ultra".

Specified by:
getLabel in interface IMeter
Returns:
this meter's fuel label

calcTotalCost

public double calcTotalCost()
Description copied from interface: IMeter
Calculate the total cost of fuel sold to this customer.

Specified by:
calcTotalCost in interface IMeter
Returns:
price/unit * number of units sold

addView

public void addView(IView aView)
Description copied from interface: IMeter
Add a view (graphical user interface) to the meter. The view's updateView method must be called each time the meter's state changes.

Specified by:
addView in interface IMeter

main

public static void main(String[] args)
Used to test the class.