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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!