|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbecker.xtras.gasPump.SampleMeter
public final class SampleMeter
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.
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 |
---|
public SampleMeter(double unitCost, int octaneRating, String theLabel)
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 |
---|
public void reset()
IMeter
reset
in interface IMeter
public void pump(double howMuch)
IMeter
pump
in interface IMeter
howMuch
- How much fuel was pumped since the last time this
method was called.public double getUnitCost()
IMeter
getUnitCost
in interface IMeter
public double getVolumeSold()
IMeter
getVolumeSold
in interface IMeter
public int getOctane()
IMeter
getOctane
in interface IMeter
public String getLabel()
IMeter
getLabel
in interface IMeter
public double calcTotalCost()
IMeter
calcTotalCost
in interface IMeter
public void addView(IView aView)
IMeter
updateView
method must be called each time the meter's state changes.
addView
in interface IMeter
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |