Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8623419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:16:33+00:00 2026-06-12T07:16:33+00:00

I’m working on a class project and I cannot seem to figure out what

  • 0

I’m working on a class project and I cannot seem to figure out what to do next. The instructions read:

• it contains a public method named getFxRate that returns a double meant to represent the exchange rate between the currency codes passed in as the first and second String arguments. The first String is the source or “in” currency, whereas the second is the destination or “out” currency.

I know i’m supposed to use that space to find out how to call one of the rates from the array, but i’m not sure how to do it.

This class will be linked to an html page, where the user will pick two currencies and then type an amount in, so getting the class to read which option they chose is another story

public class fxDataModel {

/* create array for currency codes */
private static final String[] codes = {"CAD", "EUR", "GBP", "USD"};

/* create and populate 2d array for conversion */
private static final double[][] rates = 
{ {1.0, 0.624514066, 0.588714763, 0.810307 },
  {1.601244959, 1.0, 0.942676548, 1.2975},
  {1.698615463, 1.060809248, 1.0, 1.3764},
  {1.234100162, 0.772200772, 0.726532984, 1.0} };

public String[] getFxCurrencies(){
    return codes;
}

public double getFxRate (final int inCode, final int outCode){
int inCurr, outCurr;
    double rate;

    for (inCurr = 0; inCurr < 4; inCurr++){
        String inCurrency = codes[inCurr];
        if (inCode.equals(inCurrency)) {
            break;
        }
    }

    for (outCurr = 0; outCurr < 4; outCurr++){
        String outCurrency = codes[outCurr];
        if (outCode.equals(outCurrency)) {
            break;
        }
    }

    rate = rates[inCurr][outCurr];
    return rate;

}



}

EDIT: this is the hint my professor gave us

the prototype for getFxRate is
public double getFxRate( String inCurrency, String outCurrency )
So given the inCurrency ( for example, “USD” ) and the outCurrency ( for example, “CAD” ), the method getFxRate looks in the array F/X rates and returns the one that would translate USD to CAD. Now, the array of F/X rates is double[][], that is a two dimensional array. In my hypothetical example, the value at [ 3 ][ 0 ] answers the question as to which rate in the rates array converts USD -> CAD. That’s because in the currencies array which is String[], CAD exists at the 0th position and USD exist at the 3rd. So given inCurrency and outCurrency, find there indices in the String[] array of currencies and use those indexes in the rates array to return that one single value. It’s pretty straightforward Java to loop through the array of Strings to find the matching currency and it’s associated index. That’s Java I stuff and I leave that to you, but do think loops.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:16:35+00:00Added an answer on June 12, 2026 at 7:16 am

    Currency rates are given in pairs. For example, the CADEUR rate gives you how many EUR (euros) are required to buy 1 CAD (Canadian dollar).

    Lets consider a truncated rates table:

         CAD   USD
    CAD    1   0.81 
    USD   1.23    1
    

    So if your user picks CAD and CAD as the two inputs, you return 1. If your user picks CAD and USD, you return 0.81.

    I think the problem is to take the two currency codes and to find the correct row and column number in your rates table and return the appropriate rate.

    EDIT: I would loop through the currencies array and find the index of the two currency codes given. I would use these two indexes to look up what the exchange rate should be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.