Intro à Java Programmation Convertisseur de devises entrée
Je suis tellement hors de ma profondeur dans cette classe. C'est censé être un convertisseur de devises de base. J'ai mis en évidence où j'ai des problèmes à la fois dans l'exemple et dans mon propre code. J'ai besoin de conseils sur la collecte de l'entrée et la sortie de l'entrée en fonction de mon entrée (si cela a du sens). Mon code est ci-dessous, il est encore au début.
La sortie du programme devrait ressembler à ceci ci-dessous:
(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!
===========================================================
Devise de classe publique {
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();
}
}
0
1 answers
Utilisez une instruction 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);
2
Author: Tetramputechture, 2014-10-19 04:09:40