import java.util.Scanner;
import java.text.NumberFormat;
import java.text.DecimalFormat;
/**
* Write a description of class CurrencyUI here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CurrencyUI
{
/**
* An example of a method - replace this comment with your own
*
*/
public double runConversions()
{
// put your code here
double input;
String input2;
System.out.println("Welcome to the currency converter.\n");
System.out.print("Enter the amount of American dollars to convert > ");
input = scan.nextLine();
System.out.println("Mexican Pesos [P]/nEuropean Euros [E]\nChinese Yuan [Y]\nCanadian Dollars [D]\n\nEnter the currency to convert to > ");
input2 = scan.nextLine();
System.out.println(newConversion());
}
}
Why won't this compile?
1
Expert's answer
2012-04-05T12:07:06-0400
1. line 18: add "Scanner scan = new Scanner(System.in);"
2. line 19,25:
input should be not double, but String or use this
try{
input = scan.nextDouble();
} catch(InputMismatchException e){
e.printStackTrace();
}
P.S. also, don't forget about NoSuchElementException and IllegalStateException, when You use scan.nextDouble() and scan.nextLine().
Learn more about our help with Assignments: JavaJSPJSF
Comments
Assignment Expert
17.04.12, 14:25
Sorry for delay then. You're welcome. We are glad to be helpful. If
you really liked our service please press like-button beside answer
field. Thank you!
David
14.04.12, 07:24
I'd like to personally thank you. This may or may not have helped, if
it were answered a few months ago when I was still taking the JAVA
course I was in, but I do have to say "better late than never!"
Leave a comment
Thank you! Your comments have been successfully added. However, they need to be checked by the moderator before being published.
Comments
Sorry for delay then. You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!
I'd like to personally thank you. This may or may not have helped, if it were answered a few months ago when I was still taking the JAVA course I was in, but I do have to say "better late than never!"
Leave a comment