helper
Class Piggybank

java.lang.Object
  extended by helper.Piggybank

public class Piggybank
extends java.lang.Object

This class encapsulates a piggy bank that can hold quarters and nickels (no other coins). It provides a limited variety of services, such as adding to and modifying the piggy bank.


Constructor Summary
Piggybank()
          Constructs a default piggy bank with the value of quarters as 0 and the number of nickels as 0.
 
Method Summary
 void addOneNickel()
          Add one nickel to the piggy bank
 void addOneQuarters()
          Add one quarter to the piggy bank
 boolean equals(java.lang.Object otherPiggybank)
          Checks whether this piggy bank is equal to the passed piggy bank
 int getNickels()
          Returns the number of nickels in the piggy bank
 int getQuarters()
          Returns the number of quarters in the piggy bank
 int getTotalValueOfPiggybank()
           
 int getValueOfNickels()
          Returns the value of the nickels in the piggybank in cents
 int getValueOfQuarters()
          Returns the value of the quarters in the piggybank in cents
 boolean hasSameValue(Piggybank otherPiggybank)
          Checks whether the value of the piggy bank is equal to the passed piggy bank
 void setNickels(int nickels)
          Sets the number of nickels in this piggybank to be the passed quantity.
 void setQuarters(int quarters)
          Sets the number of quarters in this piggybank to be the passed quantity.
 void shouldShowValue(boolean shouldShowValue)
          Sets whether this object, when printed out using its toProperString() method, shows itself as a monetary value or as a formatted string that lists the contents of this piggybank.
 java.lang.String toProperString()
          Returns a string representation of this Piggy Bank that is either its monetary value or a formatted description of the contents of this piggybank (in terms of the number of quarters and nickels contained in this piggy bank).
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Piggybank

public Piggybank()
Constructs a default piggy bank with the value of quarters as 0 and the number of nickels as 0.

Method Detail

addOneNickel

public void addOneNickel()
Add one nickel to the piggy bank


addOneQuarters

public void addOneQuarters()
Add one quarter to the piggy bank


getQuarters

public int getQuarters()
Returns the number of quarters in the piggy bank


setQuarters

public void setQuarters(int quarters)
Sets the number of quarters in this piggybank to be the passed quantity.

Parameters:
quarters - the number of quarters that should be in this piggybank
Throws:
java.lang.Exception - if the number of quarters is less than zerio

getNickels

public int getNickels()
Returns the number of nickels in the piggy bank


setNickels

public void setNickels(int nickels)
Sets the number of nickels in this piggybank to be the passed quantity.

Parameters:
nickels - the number of nickels that should be in this piggybank
Throws:
java.lang.Exception - if the number of nickels is less than zerio

getValueOfNickels

public int getValueOfNickels()
Returns the value of the nickels in the piggybank in cents


getValueOfQuarters

public int getValueOfQuarters()
Returns the value of the quarters in the piggybank in cents


getTotalValueOfPiggybank

public int getTotalValueOfPiggybank()

equals

public boolean equals(java.lang.Object otherPiggybank)
Checks whether this piggy bank is equal to the passed piggy bank

Overrides:
equals in class java.lang.Object

hasSameValue

public boolean hasSameValue(Piggybank otherPiggybank)
Checks whether the value of the piggy bank is equal to the passed piggy bank


shouldShowValue

public void shouldShowValue(boolean shouldShowValue)
Sets whether this object, when printed out using its toProperString() method, shows itself as a monetary value or as a formatted string that lists the contents of this piggybank.


toProperString

public java.lang.String toProperString()
Returns a string representation of this Piggy Bank that is either its monetary value or a formatted description of the contents of this piggybank (in terms of the number of quarters and nickels contained in this piggy bank). 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.