1234567891011121314151617181920212223242526272829303132 |
- enum Currency {
- usdollar (1.00),
- euro (0.94),
- bpound (0.82),
- irupee (68.32),
- aussiedollar (1.35),
- candollar (1.32),
- singdollar (1.43),
- swissfranc (1.01),
- malringgit (4.47),
- japyen (115.84),
- yuanrenminbi (6.92);
-
- private final double conversionRate;
-
- private Currency(double conversionRate) {
- this.conversionRate = conversionRate;
- }
-
- public double getConversionRate() {
- return conversionRate;
- }
-
- };
-
- public class CurrencyConverter {
- public double convertCurrency(Currency startCurrency, Currency desiredCurrency, double money) {
- money = money / startCurrency.getConversionRate() * desiredCurrency.getConversionRate();
- return Math.round(money * 100.0) / 100.0;
- }
- }
|