Question

In: Computer Science

Your task is to create a Java application that converts a specified amount of one currency...

Your task is to create a Java application that converts a specified amount of one currency into another currency for a user. The application must meet the following requirements:

1. Upon execution, the application shall display a brief welcome message to the user to let her know she is running the currency converter application.

2. The application shall allow a user to convert amounts between any two of the following currencies: United States Dollars (USD), British Pounds (GBP), Swiss Francs (CHF), and Indian Rupees (INR).

3. The application shall prompt the user for the following input: the currency she wishes to convert from (“source currency”); the amount of currency to be converted (“requested amount”) as either a decimal or a whole number (e.g., 21.45, 1.748484, or 34); and the currency she wishes to convert to (“result currency”).

4. The application shall limit the amount of the currency to be converted to no more than 1,000,000 (one million) units of that currency; if the user attempts to enter an amount larger than this number, the application should return a message alerting the user that she has exceeded the maximum amount, and prompt her to enter another amount.

5. The application shall handle incorrect user input (e.g., if the user inputs a character or string for the “requested amount” value) and prompt the user for correct input.

6. The application shall prevent the user from attempting to convert to a “result currency” that is the same as the “source currency” (e.g., the user should be prevented from converting United States Dollars to United States Dollars).

7. The application shall output the following information: the amount of the “result currency” that is equivalent to the “requested amount” in the “source currency”; this amount shall be returned as a decimal figure rounded to two decimal places (e.g., 67.49).

8. The application shall allow the user to exit the program at any time by accepting input of an exit character (for example “Q” for quit) to terminate the program.

9. After the user has successfully converted a currency, the application shall prompt the user to either perform another conversion or terminate the program.

10. Upon program termination, the application shall display an exit message to the user.

Program Data Your program should use the following data for currency conversions.

USD GBP CHF INR

USD 1.000000    1.227902 1.012514 0.013950

GBP 0.814349    1.000000 0.824820 0.011365

CHF 0.987370 1.212602 1.000000 0.013777

INR 71.687245 88.022221  72.582298  1.000000

Solutions

Expert Solution

Explanation::

  • Code in JAVA is given below
  • Screenshots of the OUTPUT are given at the end of the code


Code in JAVA::

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Currency {

   public static void main(String[] args) throws Exception{
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       System.out.println("--------------------------------------------------------------------------------");
       System.out.println(" WELCOME TO CURRENCY CONVERTER PROGRAM");
       System.out.println("Convert USD,GBP,CHF,INR");
       System.out.println("--------------------------------------------------------------------------------");

       String currency[]= {"USD","GBP","CHF","INR"};

       String sourceCurrency,resultCurrency;
       while(true) {
           while(true) {
               System.out.print("Enter the currency in which you want to enter amount(USD,GBP,CHF or INR):");
               sourceCurrency=br.readLine();
               sourceCurrency=sourceCurrency.toUpperCase();
               if(isValidCurrency(currency,sourceCurrency)) {
                   break;
               }else {
                   System.out.println("Invalid Currency Entered! Try Again.");
               }
           }
           double requestedAmount;
           while(true) {
               System.out.print("Enter request amount in "+sourceCurrency+" currency: ");
               String value=br.readLine();
               if(isDouble(value)) {
                   requestedAmount=Double.parseDouble(value);
                   if(requestedAmount<=1000000) {
                       break;
                   }else {
                       System.out.println("You exceeded the maximum amount. Enter again.");
                   }
               }else {
                   System.out.println("Invalid input! Please Try again.");
               }
           }
           while(true) {
               System.out.print("Enter the currency in which you want converted amount:");
               resultCurrency=br.readLine();
               resultCurrency=resultCurrency.toUpperCase();
               if(isValidCurrency(currency,resultCurrency) && !sourceCurrency.equals(resultCurrency)) {
                   break;
               }else {
                   System.out.println("Invalid Currency Entered! Try Again.");
               }
           }
           double answer=amount(sourceCurrency,resultCurrency,requestedAmount);
           System.out.println("The amount in "+resultCurrency+" is : "+answer);
           System.out.println("Continue? Enter Q to quit else enter anything");
           String choice=br.readLine();
           if(choice.equals("Q")) {
               System.out.println("------------------------------------------------------------------");
               System.out.println(" Program Ended");
               System.out.println("------------------------------------------------------------------");
               break;
           }
       }
   }
   public static boolean isValidCurrency(String currency[], String s) {
       for(int i=0;i<currency.length;i++) {
           if(currency[i].equals(s)) {
               return true;
           }
       }
       return false;
   }
   public static boolean isDouble(String value) {
       try {
           Double.parseDouble(value);
           return true;
       } catch (NumberFormatException e) {
           return false;
       }
   }
   public static double amount(String sourceCurrency,String resultCurrency,double requestedAmount) {
       String currency[]= {"USD","GBP","CHF","INR"};
       int index1=-1,index2=-1;
       double amountArray[][]= {
               {1.000000,1.227902,1.012514,0.013950},
               {0.814349,1.000000,0.824820,0.011365},
               {0.987370,1.212602,1.000000,0.013777},
               {71.687245,88.022221,72.582298,1.000000}
       };
       for(int i=0;i<currency.length;i++) {
           if(currency[i].equals(sourceCurrency)) {
               index1=i;
           }
           if(currency[i].equals(resultCurrency)) {
               index2=i;
           }
       }
       double multiplier=amountArray[index2][index1];

       return requestedAmount*multiplier;
   }

}

OUTPUT::

Please provide the feedback!!   

Thank You!!


Related Solutions

Your task is to create a Java application that converts a specified amount of one currency...
Your task is to create a Java application that converts a specified amount of one currency into another currency for a user. The application must meet the following requirements: Upon execution, the application shall display a brief welcome message announcing that the user is running the currency converter application. The application shall allow a user to convert amounts between any two of the following currencies: United States Dollars (USD), British Pounds (GBP), Swiss Francs (CHF), and Indian Rupees (INR). The...
You are tasked with developing an application that converts US currency ($) to 3 other major...
You are tasked with developing an application that converts US currency ($) to 3 other major world currencies. Here are the current rates: 1 US dollar = 0.90 EURO 1 US dollar = 107.7 Japanese YEN 1 US dollar =19.45 Mexican PESO Your application must prompt the user to enter an amount in US dollars, convert it into EURO, YES, and PESO and then display all using a suitable format. Coding requirements: -All your variables MUST  declared inside main() except...
Create a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
JAVACreate a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Create in java an interactive GUI application program that will prompt the user to use one...
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students” On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls:...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls: A Label control with the following text displayed: "First Number:" A Label control with the following text displayed: "Second Number:" An empty TextField control beside the First Number label. An empty TextField control beside the Second Number label. Five buttons: Button 1 labeled + Button 2 labeled - Button 3 labeled * Button 4 labeled / Button 5 labeled = An empty Label control...
Create a Java application NumberLoops to practice loops. The draft has one loop to calculate a...
Create a Java application NumberLoops to practice loops. The draft has one loop to calculate a product and the final will add another loop to print integers in a required format. There is no starter code for the problem. Use a Scanner to input an integer then compute and display the product of all positive integers that are less than the input number and multiple of 3. If no numbers satisfy the conditions, then print out 1 for the product....
Must be in Visual C# using windows forms : Create an application that opens a specified...
Must be in Visual C# using windows forms : Create an application that opens a specified text file and then displays a list of all the unique words found in the file. Hint: Use a LINQ method to remove all duplicate words.
You will write a Java Application program to perform the task of generating a calendar for...
You will write a Java Application program to perform the task of generating a calendar for the year 2020. You are required to modularize your code, i.e. break your code into different modules for different tasks in the calendar and use method calls to execute the different modules in your program. Your required to use arrays, ArrayList, methods, classes, inheritance, control structures like "if else", switch, compound expressions, etc. where applicable in your program. Your program should be interactive and...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java application. Given a set of events, choose the resulting programming actions. Understand the principles behind Java. Understand the basic principles of object-oriented programming including classes and inheritance. Deliverables .java files as requested below. Requirements Create all the panels. Create the navigation between them. Start navigation via the intro screen. The user makes a confirmation to enter the main panel. The user goes to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT