Currency

/**
 * 
 */
package com.hsbc.team.fantasy8.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 34028450
 *
 */
public class Currency {
	
	private static Map exchangeRateToUSD = new HashMap();
	
	/**
	 * 
	 */
	private Currency() {
		
	}
	
	public static double convertToUSD(String currency, double amount) {
		
		if (exchangeRateToUSD.isEmpty()) {
			exchangeRateToUSD.put("GBP", new Double("1.6213"));
			exchangeRateToUSD.put("EUR", new Double("1.3128"));
		}
		
		double usdAmount = amount;
		
		if (exchangeRateToUSD.containsKey(currency)) {
			usdAmount = amount * ((Double) exchangeRateToUSD.get(currency)).doubleValue();
		} else {
			System.out.println("*Error: Currency cannot be found");
		}
		
		return usdAmount;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(convertToUSD("GBP", 10));
		System.out.println(convertToUSD("EUR", 10));
		System.out.println(convertToUSD("CNY", 10));

	}

}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Back to Top