|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.dtt.ca.util.Money
public class Money
Class representing a quantity of money; the value can be indicated using a specific currency. This representation has no legal value and is provided only for information. This class does not provide currency exchange calculation.
Constructor Summary | |
---|---|
protected |
Money(java.lang.String currency,
int numOfDecimals)
Create an instance using a specific currency and a specic number of decimals. |
Method Summary | |
---|---|
void |
add(Money x)
Sum this amount to the amount given as parameter. |
int |
compareTo(java.lang.Object arg0)
Compares this object with the specified object for order. |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. |
java.lang.String |
getCurrency()
Get the currency adopted to indicate the price. |
int |
getDecimals()
Get the price amount in decimals of the adopted currency, e.g. 22 = 0.22 CAD The total price is given by the sum of units + decimals / (10^numOfDecimals). |
int |
getUnits()
Get the amount in units of the adopted currency, e.g. 5 = 5 JPY The total amount is given by the sum of units and cents. |
int |
hashCode()
Computes the hash code for this Money. |
void |
setValue(int units)
Set a specific amount in a specific currency |
void |
setValue(int units,
int decimals)
Set a specific amount in a specific currency The total amount is given by the sum of units and cents. |
void |
subtract(Money y)
Subtract the amount given as parameter from the current amount. |
java.lang.String |
toString()
Convert the money amount to a printable string. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected Money(java.lang.String currency, int numOfDecimals) throws UnsupportedFeatureException
currency
- a string representing the currency in the ISO 4217 interational standard.
The currency is indicated by means of three uppercase letters,
e.g. EUR, USD, JPY, CHF, AUD, CAD, CNY, GBP.numOfDecimals
- the number of decimals of this currency (0..3)
UnsupportedFeatureException
- if currency String is not a valid one.Method Detail |
---|
public final void setValue(int units)
units
- the amount in units of the indicated currency, e.g. 3 = 3 EURpublic final void setValue(int units, int decimals)
units
- the amount in units of the indicated currency, e.g. 3 = 3 EURdecimals
- the amount in decimals of the indicated currency, e.g. 18 = 0.18 USD (in this case numOfDecimals = 2)public final int getUnits()
public final int getDecimals()
public final java.lang.String getCurrency()
public final void add(Money x) throws java.lang.IllegalArgumentException
x
- the amount to add
java.lang.IllegalArgumentException
- if x is espressed in a different currencypublic final void subtract(Money y) throws java.lang.IllegalArgumentException
y
- the amount to subtract from the current amount.
java.lang.IllegalArgumentException
- if y is espressed in a different currency
java.lang.ArithmeticException
- if the result is not equal or above zeropublic java.lang.String toString()
toString
in class java.lang.Object
public int compareTo(java.lang.Object arg0)
Comparable.compareTo(java.lang.Object)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |