Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.Scanner; public class CurrencyConversion { public static void m

ID: 3641039 • Letter: I

Question

import java.util.Scanner;

public class CurrencyConversion
{
public static void main(String[] args)
{
double dollar;
double dong;

//create Scanner object for input
Scanner keyboard = new Scanner(System.in);

//prompt the user for the today's US Dollars to Vietnames Dong
System.out.println("Enter today's US Dollar to Vietnames dong exchange rate (Dong per Dollar)");
//read in this exchange rate
dollar = keyboard.nextDouble();
//inital dollars to something other than the sentinel of 0.0
double dollar = -1;

//if the user input 0, we quit the conversion
while(dollar!=0)
{
//prompt user input Dollar amount to convert to Dong with a 'type 0 to quit'
System.out.println("Enter US Dollar amount to convert to Vietnamese dong (type 0 to quit)");
money = keyboard.nextDouble();
//read into dollars
if(money==1)
{
System.out.print("1 US Dollar equals " + fot.format(input) + "Vietnamese dong. ");
}
else
{
total = money * input;
System.out.println(fot.format(money)
}
System.out.print("Goodbye!");
}

}
_____________________________________________________________________________

The code above not finish, it need some work. Please complete with following require below.



1. Currency conversion. Write a program that first asks the user to type today’s price for one dollar in Vietnamese Dong, then reads U.S. dollar values and converts each to Dong. Use 0 as a sentinel.

2. Write a program that first asks the user to type today’s price for one dollar in Vietnamese Dong, then reads U.S. dollar values and converts each to Dong. Use 0 as a sentinel value to denote the end of dollar inputs. Then the program reads a sequence of Dong amounts and converts them to dollars. The second sequence is terminated by another zero value.

Explanation / Answer

import java.text.DecimalFormat;
import java.util.Scanner;

public class CurrencyConversion {
  
    public static void main(String[] args) {
        double dollar;
        double dong;
        double rate;
        DecimalFormat fot = new DecimalFormat("###,###.00");
        Scanner keyboard = new Scanner(System.in);

        System.out.println("Enter today's US Dollar to Vietnames dong exchange rate (Dong per Dollar)");
        rate = keyboard.nextDouble();
      
        dollar = -1;
        while (dollar != 0) {
            System.out.println(" Enter US Dollar amount to convert to Vietnamese dong (type 0 to quit)");
            dollar = keyboard.nextDouble();
          
            if (dollar == 1) {
                System.out.println("1.00 US Dollar equals " + fot.format(rate) + " Vietnamese dong.");
            }
            else if (dollar != 0) {
                dong = dollar * rate;
                System.out.println(fot.format(dollar) + " US Dollars equal " + fot.format(dong) + " Vietnamese dong.");
            }
        }
      
        System.out.println("Goodbye!");
    }
}