SOURCECODE |
How to... define a new Currency
Description:
CurrencyImpl provides the outdated German currency DEUTSCHE MARK.
If you want to incorporate a new currency you will have two alternatives. You may implement interface Currency extending CatalogImpl and make your own implementation of CurrencyImpl. But this would force you to define your own MoneyBag extending CountingStockImpl, because MoneyBagImpl needs an instance of CurrencyImpl in it´s constructor.
Second alternative is to subclass CurrencyImpl and to overwrite key methods.
(See also: HowTo..incorporate a Currency and HowTo..incorporate a MoneyBag on a Currency )
ToDo's:
- Incorporate a subclass of CurrencyImpl.
- Add static attributes to characterize new Currency´s denomination.
- Add constructor (invoke superclass constructor with fitting locale ).
Tip: If you want to incorporate a new German currency, use locale.GERMANY.
Uses:
CurrencyImpl CurrencyItemImpl Currency CurrencyItem
import data.ooimpl.CurrencyImpl;
import data.ooimpl.CurrencyItemImpl;
import java.util.Locale;
1
// main class
public class CurrencyUS extends CurrencyImpl
{
2
// names of the currency items
public static String[] US$ =
{
"Cent_Coin",
"Nickel_Coin",
"Dime_Coin",
"Quarter_Coin",
"Half Dollar_Coin",
"Dollar_Coin",
"1_Dollar_Note",
"5_Dollar_Note",
"10_Dollar_Note",
"20_Dollar_Note",
"50_Dollar_Note",
"100_Dollar_Note",
};
// values of the currency items
public static int[] US$_Value =
{
1,
5,
10,
25,
50,
100,
100,
500,
1000,
2000,
5000,
10000
};
3
// constructor
public CurrencyUS (String sName)
{
// calling superclass contructor with fitting locale
super (sName, Locale.US);
// adding the items to the currency
for(int i=0; i
add (new CurrencyItemImpl (US$[i], US$_Value[i]), null);
}
}