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. 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!
Learn more about our help with Assignments:
JavaJSPJSF