CurrencyConverter.java 1.0KB

1234567891011121314151617181920212223242526272829303132
  1. enum Currency {
  2. usdollar (1.00),
  3. euro (0.94),
  4. bpound (0.82),
  5. irupee (68.32),
  6. aussiedollar (1.35),
  7. candollar (1.32),
  8. singdollar (1.43),
  9. swissfranc (1.01),
  10. malringgit (4.47),
  11. japyen (115.84),
  12. yuanrenminbi (6.92);
  13. private final double conversionRate;
  14. private Currency(double conversionRate) {
  15. this.conversionRate = conversionRate;
  16. }
  17. public double getConversionRate() {
  18. return conversionRate;
  19. }
  20. };
  21. public class CurrencyConverter {
  22. public double convertCurrency(Currency startCurrency, Currency desiredCurrency, double money) {
  23. money = money / startCurrency.getConversionRate() * desiredCurrency.getConversionRate();
  24. return Math.round(money * 100.0) / 100.0;
  25. }
  26. }