Write a program that prompts the user to enter the exchange rate from currency in U. S. dollars to Chinese RMB. Prompt the user to enter 0 to convert from U. S. dollars to Chinese RMB and 1 to convert from Chinese RMB and 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.
import java.util.Scanner;
public class USD_RMB {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the exchange rate from dollars to RMB: ");
double rate = input.nextDouble();
System.out.println("Enter 0 to convert dollars to RMB and 1 vice versa: ");
int number = input.nextInt();
if(number == 0)
System.out.println("Enter the dollar amount: ");
else if(number == 1)
System.out.println("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 " + total1 + " yuan");
else if(number == 1)
System.out.println(convert + " yuan is $" + total2);
}
}
Currently(simple example):
Exchange Rate: 6.81
Convert: 1
RMB: 10,000
output: 10000.0 yuan is $1468.4287812041116
Want:
output: 10000.0 yuan is $1468.43
Thank You.
import java.util.Scanner;
public class USD_RMB {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the exchange rate from dollars to RMB: ");
double rate = input.nextDouble();
System.out.println("Enter 0 to convert dollars to RMB and 1 vice versa: ");
int number = input.nextInt();
if(number == 0)
System.out.println("Enter the dollar amount: ");
else if(number == 1)
System.out.println("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 " + total1 + " yuan");
else if(number == 1)
System.out.println(convert + " yuan is $" + total2);
}
}
Currently(simple example):
Exchange Rate: 6.81
Convert: 1
RMB: 10,000
output: 10000.0 yuan is $1468.4287812041116
Want:
output: 10000.0 yuan is $1468.43
Thank You.