import java.util.Scanner; /**  * ii. - This program allows money to be input in one currency and then its converted to a second  * currency. The user must input the amount of money and 2 currency codes which should be USD (for dollar),   * GBP (pound) and EUR (Euro). If either of the currency codes are incorrect, the program should display an error message  * and end. If the user types in two currency codes that are the same, they should be trapped in a loop until the codes are different.  * The money should be converted to the other currancy and the value of the monies in both currencies should be displayed.   public class ChangeCurrency   {     public static void main(String[] args)     {         Scanner scan = new Scanner(System.in);                  double money = 0, convertedMoney = 0;                  String firstCurrency = "", secondCurrency = "";         //The following are the exchance rates so euroToDollar = 1.14 means 1 euro is equal to 1.14 dollars         final double euroToDollar = 1.14, euroToPound = 0.84, dollarToEuro = 0.88;         final double dollarToPound = 0.74, poundToEuro = 1.19, poundToDollar = 1.35;         System.out.print("Please enter the amount of money to convert: ");         money = scan.nextDouble();         scan.nextLine();                  /** ADD CODE HERE            1. Ask the user to input values for the first and second currency (e.g. USD for dollars, EUR for euros or GBP for pounds) and             keep user trapped until the two currencies are different.                    2. If the first and second currency do not have valid values (i.e.USD, EUR, GBP) then display an error message              otherwise write a series of IF statements that checks the values of the first and second              currencies and converts money from first to second currency storing the answer in              in convertedMoney.               For example, if converting from USD to EUR, convertedMoney will be money * 0.88                 */         System.out.println(money + firstCurrency + " converts to " + convertedMoney + secondCurrency);     }//end main }//end class

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

import java.util.Scanner;

/**
 * ii. - This program allows money to be input in one currency and then its converted to a second
 * currency. The user must input the amount of money and 2 currency codes which should be USD (for dollar), 
 * GBP (pound) and EUR (Euro). If either of the currency codes are incorrect, the program should display an error message
 * and end. If the user types in two currency codes that are the same, they should be trapped in a loop until the codes are different.
 * The money should be converted to the other currancy and the value of the monies in both currencies should be displayed.

 

public class ChangeCurrency  
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        
        double money = 0, convertedMoney = 0;
        
        String firstCurrency = "", secondCurrency = "";

        //The following are the exchance rates so euroToDollar = 1.14 means 1 euro is equal to 1.14 dollars
        final double euroToDollar = 1.14, euroToPound = 0.84, dollarToEuro = 0.88;
        final double dollarToPound = 0.74, poundToEuro = 1.19, poundToDollar = 1.35;

        System.out.print("Please enter the amount of money to convert: ");
        money = scan.nextDouble();
        scan.nextLine();
        
        /** ADD CODE HERE 
          1. Ask the user to input values for the first and second currency (e.g. USD for dollars, EUR for euros or GBP for pounds) and 
           keep user trapped until the two currencies are different.
        
          2. If the first and second currency do not have valid values (i.e.USD, EUR, GBP) then display an error message
             otherwise write a series of IF statements that checks the values of the first and second
             currencies and converts money from first to second currency storing the answer in
             in convertedMoney. 
             For example, if converting from USD to EUR, convertedMoney will be money * 0.88
        
       */

        System.out.println(money + firstCurrency + " converts to " + convertedMoney + secondCurrency);
    }//end main
}//end class

 

 

 

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY