helper
Class VendingMachine

java.lang.Object
  extended by helper.VendingMachine

public class VendingMachine
extends java.lang.Object

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

VendingMachine

public VendingMachine()
Constructs a default vending machine with the value of cansOfPop as 0 and the number of bagsOfChips as 0.


VendingMachine

public VendingMachine(int bagsOfChips,
                      int cansOfPop)
Constructs a vending machine with the passed value of cansOfPop and the passed value of bagsOfChips. Pop and bagsOfChips cannot be negative.

Throws:
java.lang.Exception - if the number of bags of chip or the number of cans of pop is less than zero
Method Detail

addBagsOfChips

public void addBagsOfChips(int bagsOfChips)
Add the passed value of bagsOfChips to the vending machine

Throws:
java.lang.Exception - if the number of bags of chip is less than zero

addCansOfPop

public void addCansOfPop(int cansOfPop)
Add the passed value of cansOfPop to the vending machine

Throws:
java.lang.Exception - if the number of cans of pop is less than zero

getCansOfPop

public int getCansOfPop()
Returns the number of cansOfPop in the vending machine


setCansOfPop

public void setCansOfPop(int cansOfPop)
Sets the number of cans of pop in this vending machine to be the passed quantity.

Parameters:
cansOfPop - the number of cans of pop that should be in this vending machine
Throws:
java.lang.Exception - if the number of cans of pop is less than zero

getBagsOfChips

public int getBagsOfChips()
Returns the number of bagsOfChips in the vending machine


setBagsOfChips

public void setBagsOfChips(int bagsOfChips)
Sets the number of bags of chips in this vending machine to be the passed quantity.

Parameters:
bagsOfChips - the number of bags of chips that should be in this vending machine
Throws:
java.lang.Exception - if the passed quantity is less than zero

getValueOfBagsOfChips

public double getValueOfBagsOfChips()
Returns the value of the bags of chips contained in this vending machine in dollars


getValueOfCansOfPop

public double getValueOfCansOfPop()
Returns the value of the cans of pop contained in this vending machine in dollars


getTotalValueOfVendingmachine

public 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


mergeContents

public void mergeContents(VendingMachine otherVendingmachine)
Adds the contents of the passed vending machine to the contents of this vending machine.


equals

public 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.

Overrides:
equals in class java.lang.Object

shouldShowValue

public 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.


valueEquals

public 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


toProperString

public 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). Which of these two options is used depends on this objects state with respect to shouldShowValue (see the method shoudShowValue(boolean). The default option is the first one.