67 072
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #4710 in Java | JSP | JSF for David Hughes

Question #4710
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?
Expert's answer
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().


Good luck =)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

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

Ask Your question

Submit
Privacy policy Terms and Conditions