Question
write a program that prompt the user to enter the exchange rate from currency in U.S dollar to chinese RMB . Prompt the user to
write a program that prompt the user to enter the exchange rate from currency in U.S dollar to chinese RMB . Prompt the user to enter 0 to convert from U.S. dollar to chinese RMB AND 1 to convert from chinese RMB and U.S dollar. Prompt the user to enter the amount in U.S dollar or chinese RMB to convert it to chinese RMB or U.S. dollar
Here is the solution but it has some errors I need to fix them . Please help:
import java.text.DecimalFormat; import java.util.Scanner;
/** * @author Srinivas Palli * */ public class USDRMBConversion {
/** * @param args */ public static void main(String[] args) { Scanner input = new Scanner(System.in); DecimalFormat df = new DecimalFormat("0.00"); System.out.print("Enter the exchange rate from dollars to RMB: "); double rate = input.nextDouble();
System.out .print(" Enter 0 to convert dollars to RMB and 1 vice versa: "); int number = input.nextInt();
if (number == 0) System.out.print(" Enter the dollar amount: "); else if (number == 1) System.out.print(" Enter the RMB amount: "); else System.out.println("Incorrect input"); double convert = input.nextDouble();
double total1 = rate * convert; double total2 = convert / rate; if (number == 0) System.out.println("$" + convert + " is " + df.format(total1) + " yuan"); else if (number == 1) System.out.println(convert + " yuan is $" + df.format(total2));
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started