Question

In: Computer Science

Programming language is Java In this second assignment, you will calculate currency conversions from United States...

Programming language is Java

In this second assignment, you will calculate currency conversions from United States Dollars (USD) to Indian Rupees (INR) or to Euros (EUR) or to British Pounds (GB) using methods and formatting the results.

Use these ratios: 1 USD to 72.282250 INR 1 USD to 0.913465 EUR 1 USD to 0.833335 GBP

Your task is to write a program that

• displays a menu to choose conversion from dollars to rupees, euros, or pounds.

• displays the exchange rate for the currency chosen

• prompts the user for amount of dollars to convert and displays the result

• prompts the user for amount of currency to convert to dollars and displays the result

• displays a message thanking the user.

• If user chooses a menu selection outside the range, display an error message.

You will use these two EXACT method headers to define methods that will calculate the conversions and return the results:

public static double calcUSDtoCurrency(double amountToConvert, double rate) public static double calcCurrencyToUSD(double amountToConvert, double rate)

Format each currency using the NumberFormat class. You may use the following parameters for the getCurrencyInstance method or you may research to find another way (be sure to document your sources):

Locale.US new Locale(“en”, “IN”) Locale.GERMANY new Locale(“en”, “GB”)

*Note: for those already familiar with Java programming, please keep this simple: no arrays, nothing fancy. Please use only the concepts discussed in class & in Chapters 1, 2, 3, 4, 6, and NumberFormat class.

Before starting this lab, be sure to refer to the “How to Submit Assignments” document in eLearn for proper zipping, documentation, indention, naming conventions, etc. Points may be deducted if submitted incorrectly.

Required project name: LastnameFirstname02 Required package name: chap46

Required class name: ConverterMethods

Here are 4 sample runs of the program. Your program should display something similar. User input is green text.

Currency Converter

1. Convert USD to Indian Rupee

2. Convert USD to Euro

3. Convert USD to British Pounds

What would you like to do? 1

Exchange rate assumed to be 1 US Dollar to 72.28225 Indian Rupees

How many dollars would you like to convert to rupees: 123.45 You will receive Rs.8,923.24 for $123.45

How many rupees would you like to convert to dollars: 1234.56 You will receive Rs.17.08 for $1,234.56

Thank you for using the Currency Converter

Currency Converter

1. Convert USD to Indian Rupee

2. Convert USD to Euro

3. Convert USD to British Pounds

What would you like to do? 2

Exchange rate assumed to be 1 US Dollar to

How many dollars would you like to convert

You will receive 112,77 € for $123.45

0.913465 Euros to euros: 123.45

How many euros would you like to convert to dollars: 1234.56 You will receive $1,351.51 for 1.234,56 €

Thank you for using the Currency Converter

Currency Converter

1. Convert USD to Indian Rupee

2. Convert USD to Euro

3. Convert USD to British Pounds

What would you like to do? 3

Exchange rate assumed to be 1 US Dollar to

How many dollars would you like to convert

You will receive £102.88 for $123.45

0.833335 British Pounds to pounds: 123.45

How many pounds would you like to convert to dollars: 1234.56 You will receive $1,481.47 for £1,234.56

Thank you for using the Currency Converter

Currency Converter

1. Convert USD to Indian Rupee

2. Convert USD to Euro

3. Convert USD to British Pounds

What would you like to do? 4

I'm sorry, 4 isn't a valid choice.

  

Helpful Notes:

Primitive type variables should begin with lowercase.

Constant variables should be all uppercase (that’s a big hint that you should include constants). To save resources, use the fewest number of variables possible. When getting user input, use just ONE variable named something like userInput or amountToConvert. Likewise, after all calculations, use just ONE variable named something like results or conversion.

If you expect a specific data type from the user, the input should be stored as that data type.

Solutions

Expert Solution

package currencyc;
import java.util.Scanner;
public class CurrencyConverter {
   static Scanner s=new Scanner(System.in);
   static double INR=72.282250;
   static double EUR=0.913465;
   static double GBP=0.833335;
   static double amount;
   static double dollar;
   public static double calcUSDtoCurrency(double amountToConvert,double rate)
   {
      
       amount=dollar*rate;  
      
       return amount;
   }
  
   public static double calcCurrencyToUSD(double amountToConvert,double rate)
   {
       dollar=amountToConvert/rate;
       return dollar;
   }
  
   public static void main(String args[])
   {
       int ch;
       do
       {
       System.out.println("Currency Converter");
       System.out.println("1. Convert USD to Indian Rupee");
       System.out.println("2. Convert USD to Euro");
       System.out.println("3. Convert USD to British Pounds");
       System.out.println("What would you like to do?");
       ch=s.nextInt();
       switch(ch)
       {
       case 1:
           System.out.println("Exchange rate assumerd to be 1 US Dollar to 72.28225 Indian Rupees");
           System.out.println("How many Dollars would you like to convert to rupees:");
           dollar=s.nextDouble();
           amount=calcUSDtoCurrency(dollar,INR);
           System.out.println("You will receive Rs."+amount+" for $"+dollar);
           System.out.println("How many Rupees would you like to convert to Dollars:");
           amount=s.nextDouble();
           dollar=calcCurrencyToUSD(amount,INR);
           System.out.println("You will receive $."+dollar+" for Rs."+amount);
           System.out.println("Thank you for using the Currency Converter");
           break;
       case 2:
           System.out.println("Exchange rate assumerd to be 1 US Dollar to 0.913465 Euros");
           System.out.println("How many Dollars would you like to convert to Euros:");
           dollar=s.nextDouble();
           amount=calcUSDtoCurrency(dollar,EUR);
           System.out.println("You will receive € "+amount+" for $"+dollar);
           System.out.println("How many Euros would you like to convert to Dollars:");
           amount=s.nextDouble();
           dollar=calcCurrencyToUSD(amount,EUR);
           System.out.println("You will receive $."+dollar+" for €"+amount);
           System.out.println("Thank you for using the Currency Converter");
           break;
       case 3:
           System.out.println("Exchange rate assumerd to be 1 US Dollar to 0.833335 British Pounds");
           System.out.println("How many Dollars would you like to convert to British Pounds:");
           dollar=s.nextDouble();
           amount=calcUSDtoCurrency(dollar,GBP);
           System.out.println("You will receive £ "+amount+" for $"+dollar);
           System.out.println("How many Euros would you like to convert to Dollars:");
           amount=s.nextDouble();
           dollar=calcCurrencyToUSD(amount,GBP);
           System.out.println("You will receive $."+dollar+" for £"+amount);
           System.out.println("Thank you for using the Currency Converter");
           break;
       case 4:
          
           System.out.println("I'm sorry, 4 isn't a valid choice.");
           break;
          
       }
       }while(ch<=3);
      
  
   }

}

output:

Currency Converter
1. Convert USD to Indian Rupee
2. Convert USD to Euro
3. Convert USD to British Pounds
What would you like to do?
1
Exchange rate assumerd to be 1 US Dollar to 72.28225 Indian Rupees
How many Dollars would you like to convert to rupees:
123.45
You will receive Rs.8923.2437625 for $123.45
How many Rupees would you like to convert to Dollars:
1234.56
You will receive $.17.079711824133863 for Rs.1234.56
Thank you for using the Currency Converter
Currency Converter
1. Convert USD to Indian Rupee
2. Convert USD to Euro
3. Convert USD to British Pounds
What would you like to do?
2
Exchange rate assumerd to be 1 US Dollar to 0.913465 Euros
How many Dollars would you like to convert to Euros:
123.45
You will receive € 112.76725425 for $123.45
How many Euros would you like to convert to Dollars:
1234.56
You will receive $.1351.5131942657902 for €1234.56
Thank you for using the Currency Converter
Currency Converter
1. Convert USD to Indian Rupee
2. Convert USD to Euro
3. Convert USD to British Pounds
What would you like to do?
3
Exchange rate assumerd to be 1 US Dollar to 0.833335 British Pounds
How many Dollars would you like to convert to British Pounds:
123.45
You will receive £ 102.87520575 for $123.45
How many Euros would you like to convert to Dollars:
1234.56
You will receive $.1481.4690370619257 for £1234.56
Thank you for using the Currency Converter
Currency Converter
1. Convert USD to Indian Rupee
2. Convert USD to Euro
3. Convert USD to British Pounds
What would you like to do?
4
I'm sorry, 4 isn't a valid choice.


Related Solutions

PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
Your task is to modify the program from the Java Arrays programming assignment to use text...
Your task is to modify the program from the Java Arrays programming assignment to use text files for input and output. I suggest you save acopy of the original before modifying the software. Your modified program should: contain a for loop to read the five test score into the array from a text data file. You will need to create and save a data file for the program to use. It should have one test score on each line of...
For this assignment I want you to assume you are the President of the United States,...
For this assignment I want you to assume you are the President of the United States, and China (one of our largest export customers) decides to ban all imports from the U.S. What effect would that have on the U.S. economy? Consider AD, unemployment, inflation, and recession as you contemplate your answer. Once you have determined a potential danger to our economy, what fiscal policy tool would you use to mitigate the damage of China’s decision?
please answer with coding from The second edition C programming language textbook /* Changes all occurrences...
please answer with coding from The second edition C programming language textbook /* Changes all occurrences of t in s to u, result stored in v * * Example: * * char v[100]; * replace("hello", "el", "abc", v) => v becomes "habclo" * replace("", "el", "abc", v) => v becomes "" (no change) * replace("hello", "abc", "def", v) => v becomes "hello" (no change) * replace("utilities", "ti", "def", v) => v becomes "udeflidefes" * */ void replace(char *s, char *t,...
In JAVA Language Please! Programming Exercise 3.20 required you to design a PID manager that allocated...
In JAVA Language Please! Programming Exercise 3.20 required you to design a PID manager that allocated a unique process identifier to each process. Exercise 4.20 required you to modify your solution to Exercise 3.20 by writing a program that created a number of threads that requested and released process identifiers. Now modify your solution to Exercise 4.20 by ensuring that the data structure used to represent the availability of process identifiers is safe from race conditions. Use Pthreads mutex locks....
Which currency area, the 50 states of the United States or the member nations of the...
Which currency area, the 50 states of the United States or the member nations of the euro-zone, performs better as an optimum currency area?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT