Question
In Java Please (Don't copy other answers),Please help Currency Exchange Programming challenge description: Given A list of foreign exchange rates A selected curreny A target
In Java Please (Don't copy other answers),Please help
Currency Exchange
Programming challenge description:
Given
- A list of foreign exchange rates
- A selected curreny
- A target currency
Your goal is to calculate the max amount of the target currency to 1 unit of the selected currency through the FX transactions. Assume all transations are free and done immediately. If you cannot finish the exchange, return -1.0.
Input:
You will be provided a list of fx rates, a selected currency, and a target currency.
For example:
FX rates list: USD to JPY 1 to 109 USD to GBP 1 to 0.71 GBP to JPY 1 to 155 Original currency: USD Target currency : JPY
Output:
Calculated the max target currency will can get.
For example:
USD to JPY -> 109 USD to GBP to JPY = 0.71 * 155 = 110.05 > 109,
so the max value will be 110.05
Test 1
Test InputDownload Test 1 Input
USD,CAD,1.3;USD,GBP,0.71;USD,JPY,109;GBP,JPY,155 USD JPY
Expected OutputDownload Test 1 Input
110.05
Test 2
Test InputDownload Test 2 Input
USD,GBP,0.7;USD,JPY,109;GBP,JPY,155;CAD,CNY,5.27;CAD,KRW,921 USD CNY
Expected OutputDownload Test 2 Input
-1.0
Given code in Java:
import java.nio.charset.StandardCharsets;
/** * The Main class implements an application that reads lines from the standard input * and prints them to the standard output. */ public class Main { /** * Iterate through each line of input. */ public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(reader); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started