All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class banking.Money

java.lang.Object
   |
   +----banking.Money

public class Money
extends Object
Representation for money amounts


Variable Index

 o cents
Instance variable: this amount represented as a number of cents

Constructor Index

 o Money(int)
Constructor
 o Money(int, int)
Constructor
 o Money(Money)
Copy constructor

Method Index

 o add(Money)
Add an amount of money to this
 o lessEqual(Money)
Compare this to another amount
 o subtract(Money)
Subtract an amount of money from this
 o toString()
Create a string representation of this amount

Variables

 o cents
 private long cents
Instance variable: this amount represented as a number of cents

Constructors

 o Money
 public Money(int dollars)
Constructor

Parameters:
dollars - whole dollar amount
 o Money
 public Money(int dollars,
              int cents)
Constructor

Parameters:
dollars - dollar part of amount
cents - cents part of amount
 o Money
 public Money(Money toCopy)
Copy constructor

Parameters:
toCopy - the Money object to copy

Methods

 o toString
 public String toString()
Create a string representation of this amount

Returns:
string representation of this amount
Overrides:
toString in class Object
 o add
 public void add(Money amountToAdd)
Add an amount of money to this

Parameters:
amountToAdd - the amount to add
 o subtract
 public void subtract(Money amountToSubtract)
Subtract an amount of money from this

Parameters:
amountToSubtract - the amount to subtract Precondition: amount must be <= this amount
 o lessEqual
 public boolean lessEqual(Money compareTo)
Compare this to another amount

Parameters:
compareTo - the amount to compare to
Returns:
true if this amount is <= compareTo amount

All Packages  Class Hierarchy  This Package  Previous  Next  Index