0% found this document useful (0 votes)
7 views1 page

CurrencyConverter Java

The CurrencyConverter class facilitates currency conversion using provided exchange rates. It has a constructor that initializes the currency rates and a method to convert an amount from one currency to another based on the rates. The conversion is performed by dividing the amount by the source currency rate and multiplying by the target currency rate.

Uploaded by

ritu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

CurrencyConverter Java

The CurrencyConverter class facilitates currency conversion using provided exchange rates. It has a constructor that initializes the currency rates and a method to convert an amount from one currency to another based on the rates. The conversion is performed by dividing the amount by the source currency rate and multiplying by the target currency rate.

Uploaded by

ritu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

package [Link].

converter;

public class CurrencyConverter {


private final CurrencyRates rates;

public CurrencyConverter(CurrencyRates rates) {


[Link] = rates;
}

public double convert(String from, String to, double amount) {


double fromRate = [Link](from);
double toRate = [Link](to);
return (amount / fromRate) * toRate;
}
}

You might also like