Please use java for the following!!! Write a program that prompts the user to en
ID: 3670040 • Letter: P
Question
Please use java for the following!!!
Write a program that prompts the user to enter the exchange rate from currency in U.S. dollars to Chinese RMB (in other words, how many RMB are equivalent to 1 U.S. dollar?). Prompt the user to enter 0 to convert from U.S. dollars to Chinese RMB and 1 to convert from Chinese RMB to U.S. dollars. Prompt the user to enter the amount in U.S. dollars or Chinese RMB to convert it to Chinese RMB or U.S. dollars, respectively.
Here is a sample run:
Enter the exchange rate from dollars to RMB: 6.81
Enter 0 to convert dollars to RMB and 1 vice versa: 0
Enter the dollar amount: 100
$100.0 is 681.0 yuan
Explanation / Answer
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
float exchange;
float dollar,yuan;
int choice;
Scanner in = new Scanner(System.in);
System.out.print("Enter the exchange rate from dollars to RMB: ");
exchange = in.nextFloat();
System.out.print("Enter 0 to convert dollars to RMB and 1 vice versa: ");
choice = in.nextInt();
if(choice==0)
{
System.out.print("Enter the dollar amount: ");
dollar = in.nextFloat();
yuan = dollar*exchange;
System.out.print("$"+dollar+" is "+yuan+" yuan ");
}else{
System.out.print("Enter the yuan amount: ");
yuan = in.nextFloat();
dollar = yuan/exchange;
System.out.print(""+yuan+" yuan is $"+dollar);
}
}
}