Java编程货币转换器输入简介

时间:2014-10-19 03:40:05

标签: java input output currency

我在这堂课中超出了我的深度。它应该是一个基本的货币转换器。我突出了我在示例和示例中遇到问题的地方。我自己的代码。我需要收集输入和输入的建议。根据我的输入输出输入(如果这是有意义的)。我的代码如下,它还处于起步阶段。

程序的输出如下所示:

(Example) Welcome to the Currency Converter Program (Example)

Use the following codes to input your currency choices:
    1 – US Dollars
    2 – Euros 
    3 – British Pounds
    4 – Japanese Yen

Please choose the input currency: 2

Now choose the output currency: 1

Now enter the input in *Euros*: €10.00 <--- *This is where I am stuck at right now. How
can I get the output to say Euro's, dollars, yen, etc. depending on what my input 
currency is?*


€10.00 Euros at a conversion rate of 1.5 Euros to Dollars = $15.00 US Dollars.


Thank you for using the Currency Converter Program!


===========================================================

公共类货币 {

 public currency()
{
    char us_dollar_sym = 36;
    char pound_sym = 163;
    char yen_sym = 165;
    char euro_sym = 8364; 

    double us_dollar = 0; 
    double pound = 0;
    double yen = 0;
    double euro =0;

    // Interface
    System.out.println("Welcome to the Currency Converter Program \n");
    System.out.println("Use the following codes to input your currency choices: \n 1 - US dollars \n 2 - Euros \n 3 - British Pounds \n 4 - Japanese Yen \n");

    // Collect user input
    System.out.println("Please choose the input currency:");
    Scanner in = new Scanner(System.in);
    String choice = in.next(); 

    System.out.println("Please choose the output currency");
    String output = in.next();

    System.out.printf("Now enter the input in"); <-- Stuck here 
    double input = in.nextInt(); 



}

}

1 个答案:

答案 0 :(得分:2)

使用switch声明。

System.out.println("Please choose the input currency:");
Scanner in = new Scanner(System.in);
String choice = in.next(); 

String inType;
switch(choice) {
    case "1":
        inType = "US Dollars";
        break;
    // etc...
    default:
        inType = null;
        System.out.println("Please enter a correct currency type from the list.");
}

System.out.printf("Now enter the input in" + inType);