Class Money

java.lang.Object
|
+--Money

public class Money
extends java.lang.Object

Money represents an amount of dollars and cents.


Field Summary
static int CENTS
          The number of cents in a dollar.
 
Constructor Summary
Money()
          Creates a new amount of Money with 0 dollars and 0 cents.
Money(int dollars)
          Creates a new amount of Money with the given amount of dollars and 0 cents.
Money(int dollars, int cents)
          Creates a new amount of Money with the given amount of dollars and cents.
 
Method Summary
 void addMoney(Money amount)
          Adds the given amount of Money to this amount of Money.
 int getCents()
          Returns the number of cents in this amount of Money.
 int getDollars()
          Returns the number of dollars in this amount of Money.
 boolean isEqual(Money amount)
          Determines if this amount of Money is equal to the given amount of Money.
 boolean isGreater(Money amount)
          Determines if this amount of Money is greater than the given amount of Money.
 java.lang.String toString()
          Returns a String which represents the amount of dollars and cents in this amount of Money.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CENTS

public static final int CENTS
The number of cents in a dollar.

Constructor Detail

Money

public Money()
Creates a new amount of Money with 0 dollars and 0 cents.


Money

public Money(int dollars)
Creates a new amount of Money with the given amount of dollars and 0 cents.

Parameters:
dollars - if positive, the number of dollars; otherwise, 0

Money

public Money(int dollars,
int cents)
Creates a new amount of Money with the given amount of dollars and cents.

Parameters:
dollars - if positive, the number of dollars; otherwise, 0
cents - if between 0 and CENTS, the number of cents; otherwise, 0
Method Detail

toString

public java.lang.String toString()
Returns a String which represents the amount of dollars and cents in this amount of Money.

Overrides:
toString in class java.lang.Object
Returns:
'n dollars and m cents'

getDollars

public int getDollars()
Returns the number of dollars in this amount of Money.

Returns:
the number of dollars

getCents

public int getCents()
Returns the number of cents in this amount of Money.

Returns:
the number of cents

addMoney

public void addMoney(Money amount)
Adds the given amount of Money to this amount of Money.
The amount of cents will stay between 0 and CENTS.

Parameters:
amount - the amount of Money to add

isEqual

public boolean isEqual(Money amount)
Determines if this amount of Money is equal to the given amount of Money.

Parameters:
amount - the amount of Money to compare with
Returns:
true, if this amount has the same number of dollars and cents as the given amount

isGreater

public boolean isGreater(Money amount)
Determines if this amount of Money is greater than the given amount of Money.

Parameters:
amount - the amount of Money to compare with
Returns:
true, if this amount is more than the given amount