|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecthelper.VendingMachine
public class VendingMachine
This class encapsulates a vending bank that can hold bags of chips and cans of pop (no other type of food). It provides a limited variety of services, such as adding to and modifying the contents of the vending machine.
Constructor Summary | |
---|---|
VendingMachine()
Constructs a default vending machine with the value of cansOfPop as 0 and the number of bagsOfChips as 0. |
|
VendingMachine(int bagsOfChips,
int cansOfPop)
Constructs a vending machine with the passed value of cansOfPop and the passed value of bagsOfChips. |
Method Summary | |
---|---|
void |
addBagsOfChips(int bagsOfChips)
Add the passed value of bagsOfChips to the vending machine |
void |
addCansOfPop(int cansOfPop)
Add the passed value of cansOfPop to the vending machine |
boolean |
equals(java.lang.Object otherVendingmachine)
Checks whether this vending machine is equal to the passed vending machine, where two machines are considered equal if their contents have the same number of cans of pop and the same number of bags of chips. |
int |
getBagsOfChips()
Returns the number of bagsOfChips in the vending machine |
int |
getCansOfPop()
Returns the number of cansOfPop in the vending machine |
double |
getTotalValueOfVendingmachine()
Returns the value of the contents of this vending machine (defined as all the bags of chips and cans of pop) in dollars |
double |
getValueOfBagsOfChips()
Returns the value of the bags of chips contained in this vending machine in dollars |
double |
getValueOfCansOfPop()
Returns the value of the cans of pop contained in this vending machine in dollars |
void |
mergeContents(VendingMachine otherVendingmachine)
Adds the contents of the passed vending machine to the contents of this vending machine. |
void |
setBagsOfChips(int bagsOfChips)
Sets the number of bags of chips in this vending machine to be the passed quantity. |
void |
setCansOfPop(int cansOfPop)
Sets the number of cans of pop in this vending machine to be the passed quantity. |
void |
shouldShowValue(boolean shouldShowValue)
Sets whether this object, when printed out using its toProperString() method, should shows itself as the monetary value of its contents or as a formatted string that lists the contents of this vending machine. |
java.lang.String |
toProperString()
Returns a string representation of this vending machine that is either the monetary value of its contents or a formatted description of the contents of this vending machine (in terms of the number of bags of chips and cans of pop contained in this vending machine). |
boolean |
valueEquals(VendingMachine otherVendingmachine)
Checks whether the value of the contents of this vending machine is equal to the value of the contents of the passed vending machine |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public VendingMachine()
public VendingMachine(int bagsOfChips, int cansOfPop)
java.lang.Exception
- if the number of bags of chip or the number of cans of pop is
less than zeroMethod Detail |
---|
public void addBagsOfChips(int bagsOfChips)
java.lang.Exception
- if the number of bags of chip is less than zeropublic void addCansOfPop(int cansOfPop)
java.lang.Exception
- if the number of cans of pop is less than zeropublic int getCansOfPop()
public void setCansOfPop(int cansOfPop)
cansOfPop
- the number of cans of pop that should be in this vending
machine
java.lang.Exception
- if the number of cans of pop is less than zeropublic int getBagsOfChips()
public void setBagsOfChips(int bagsOfChips)
bagsOfChips
- the number of bags of chips that should be in this vending
machine
java.lang.Exception
- if the passed quantity is less than zeropublic double getValueOfBagsOfChips()
public double getValueOfCansOfPop()
public double getTotalValueOfVendingmachine()
public void mergeContents(VendingMachine otherVendingmachine)
public boolean equals(java.lang.Object otherVendingmachine)
equals
in class java.lang.Object
public void shouldShowValue(boolean shouldShowValue)
public boolean valueEquals(VendingMachine otherVendingmachine)
public java.lang.String toProperString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |