Question

Create a currency converter java program. It will store conversion rates between some currency and the...

Create a currency converter java program. It will store conversion rates between some currency and the US$ for a month. The program flow is as follows:

(Part 1)Get user input for the historical data.

  • Historical data will be the currency, day of the month (1-31) and conversion rate. Keep getting input until a null or space is entered for the currency.  
  • Assume 3 currencies max will be entered.
  • Store data in a 2-dimensional array. Maybe 32 rows by 5 columns matrix. Rows are day of month, columns are currency. Each cell will store the rate that was input for that Currency/Day of Month pair.
  • Once 3 unique currencies are entered, do not accept any more unique currencies.

(Part 2) Get user input to lookup rates

  • User will input a currency, day of the month and an amount.
  • You will check if a rate exists for that currency & day. If it does you will multiply the amount by the rate and output the US$ equivalent. If the currency/date pair doesn't exist or there's no rate for it, output "Data Not Available"
  • Keep requesting input until the user enters null or space for currency and then terminate the program

Example program output:

Enter Historical Data (Currency, Day of Month, Rate): EUR, 1, 1.11

Enter Historical Data (Currency, Day of Month, Rate): EUR, 2, 1.10

Enter Historical Data (Currency, Day of Month, Rate): JPY, 1, .0092

.....

Enter Historical Data (Currency, Day of Month, Rate): GBP, 31, 1.24

Enter Historical Data (Currency, Day of Month, Rate): [user enters null]

Enter Conversion Lookup(Currency, Day of Month, Amount): EUR, 1, 1000.00

1000.00 EUR = 1100.00 US$

Enter Conversion Lookup(Currency, Day of Month, Amount): GBP, 5, 2000.00

Data Not Available

Enter Conversion Lookup(Currency, Day of Month, Amount): GBP, 1, 1000.00

2000.00 GBP = 1300.00 US$

Enter Conversion Lookup(Currency, Day of Month, Amount): [user enters null]

program terminates

You can assume that days will be 1-31 but currencies and rates are dependent on user input.

Historical Data for exchange rates:

EUR GBP    MXN JPY
1 1.10 1.30 18.59 109.80
2 1.10 1.29 18.65 110.00
3 1.09 1.28 18.76 109.73
4 1.09 1.29 18.76 109.73
5 Unavailable Unavailable Unavailable Unavailable
6 1.09 1.29 18.70 109.77
7 1.09 1.29 18.67 109.79
8 1.09 1.30 18.63 110.08
9 1.08 1.31 18.60 109.82
10 1.08 1.30 18.54 109.77
11 1.08 1.30 18.54 109.80
12 Unavailable Unavailable Unavailable Unavailable
13 1,08 1.30 18.56 109.85
14 1.08 1.30 18.59 109.86
15 1.08 1.29 18.57 111.25
16 1.08 1.29 18.84 112.06
17 1.08 1.30 18.91 111.58
18 1,08 1.,30 18.91 111.58
19 Unavailable Unavailable Unavailable Unavailable
20 1.09 1.29 19.08 110.67
21 1.09 1.30 19.09 110.21
22 1.09 1.29 19.29 110.41
23 1.10 1.29 19.50 109.53
24 1.10 1.28 19.62 108.12
25 1.10 1.28 19.62 108.12
26 Unavailable Unavailable Unavailable Unavailable
27 1.11 1.28 19.40 108.31
28 1.12 1.28 19.46 107.16
29 1.11 1.29 19.52 107.56
30 1.12 1.30 19.86 106.15
31 1.12 1.30 20.05 106.26
0 0
Add a comment Improve this question Transcribed image text
Answer #1


package HomeworkLib;

import java.util.Arrays;
import java.util.Scanner;

public class CurrencyConverter {
    protected static String[][] data =new String[32][4];
    public static void main(String[] args){

        System.out.println("Get Historical Data");
        initializeTable();
        loadHistoricalData();

        //System.out.println("Currency Loopup");
        currencyLookup();

        for(int i=0;i<data.length;i++)
            System.out.println(Arrays.toString(data[i]));
    }

    private static void initializeTable() {
        for(int i=1;i<data.length;i++){
            data[i][0] =Integer.toString(i);
            for(int j=1;j<data[0].length;j++){
                data[i][j]="Unavailable";
            }
        }
    }

    private static void currencyLookup() {
        String line,currency;
        String[] row=null;
        int day;
        boolean isCurrencyFound =false;
        double amount,convertedAmount;
        Scanner scanner =new Scanner(System.in);
        System.out.println("Enter Currency Loopup Data (Currency, Date of Month, Amount): ");
        line =scanner.next();

        while (true){
            convertedAmount=0; isCurrencyFound=false;
            row =line.split(",", -1);
            currency=row[0];
            day=Integer.parseInt(row[1]);
            amount=Double.parseDouble(row[2]);
            if(currency ==null || currency.trim() =="" || currency.trim().length()==0){
                break;
            }

            //Calculate the Amount
            int i;
            for(i=1;i<data[0].length;i++){
                if(data[0][i].equalsIgnoreCase(currency)){
                    isCurrencyFound=true;
                    if(("Unavailable").equalsIgnoreCase(data[day][i])){
                        System.out.println("Data not available");
                        break;
                    }
                    convertedAmount=amount * Double.parseDouble(data[day][i]);

                    break;
                }
            }
            if(isCurrencyFound)
                System.out.println(amount +currency+"="+convertedAmount);
            else
                System.out.println("Allowed Curency:"+Arrays.toString(data[0]));
            System.out.println("Enter Currency Loopup Data (Currency, Date of Month, Amount): ");
            line =scanner.next();
        }
    }

    private static void loadHistoricalData() {
        String line=null,rate,currency;
        boolean isCurrencyAllowed=false;
        int day;
        String[] row;
        Scanner scanner =new Scanner(System.in);
        System.out.println("Enter Historial Data (Currency, Date of Month, Rate): ");
        line =scanner.next();
        while(true){
            isCurrencyAllowed=false;
            row =line.split(",", -1);
            currency=row[0];
            day=Integer.parseInt(row[1]);
            rate=row[2];
            if(currency ==null || currency.trim() =="" || currency.trim().length()==0){
                break;
            }
            for(int i=1;i<data[0].length;i++){
                if(data[0][i] =="" || data[0][i] ==null){
                    data[0][i] =currency;
                    data[day][i]=rate;
                    isCurrencyAllowed=true;
                    break;
                }
                if(currency.equalsIgnoreCase(data[0][i])){
                    data[day][i] =rate;
                    isCurrencyAllowed=true;
                    break;
                }
            }
            if (!isCurrencyAllowed) System.out.println("Only 3 Currency Allowed:"+Arrays.toString(data[0]));
            System.out.println("Enter Historial Data (Currency, Date of Month, Rate): ");
            line =scanner.next();
        }
        System.out.println("Data Loading Done");
    }
}
Add a comment
Know the answer?
Add Answer to:
Create a currency converter java program. It will store conversion rates between some currency and the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is a python question. Start with this program, import json from urllib import request def...

    This is a python question. Start with this program, import json from urllib import request def main(): to_continue = 'Yes' while to_continue == 'yes' or to_continue == 'Yes': currency_code = input("Enter currency code: ").upper() dollars = int(input("Enter number of dollar you want to convert: ")) # calling the exchange_rates function data = get_exchange_rates() if currency_code in data["rates"].keys(): currency = data["rates"][currency_code] # printing the the currency value by multiplying the dollars amount. print("The value is:", str(currency * dollars)) else: print("Error: the...

  • Please write this in Java, please write comments as you create it, and please follow the...

    Please write this in Java, please write comments as you create it, and please follow the coding instructions. As you are working on this project, add print statements or use the debugger to help you verify what is happening. Write and test the project one line at a time. Before you try to obtain currency exchange rates, obtain your free 32 character access code from this website: https://fixer.io/ Here's the code: 46f27e9668fcdde486f016eee24c554c Choose five international source currencies to monitor. Each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT