This commit is contained in:
louiscklaw
2025-01-31 19:15:17 +08:00
parent 09adae8c8e
commit 6c60a73f30
1546 changed files with 286918 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
class CurrencyConverter {
private double exchangeRate;
private double commissionRate;
private int largeAmount;
public CurrencyConverter(double er , double cr){
exchangeRate = er;
commissionRate = cr;
}
public double fromUSDollar(double dollar){
if (dollar >= largeAmount)
return (dollar * exchangeRate * (1-commissionRate*0.5));
else
return (dollar * exchangeRate * (1-commissionRate));
}
public double toUSDollar(double foreignMoney){
if (foreignMoney/exchangeRate >= largeAmount)
return (foreignMoney/exchangeRate*(1-commissionRate*0.5));
else
return (foreignMoney/exchangeRate*(1-commissionRate));
}
public void setExchangeRate(double rate){
exchangeRate = rate;
}
public double getExchangeRate(){
return exchangeRate;
}
public void setCommissionRate(double rate){
commissionRate = rate;
}
public double getCommissionRate(){
return commissionRate;
}
public void setLargeAmount(int amount){
largeAmount = amount;
}
public int getLargeAmount(){
return largeAmount;
}
}

View File

@@ -0,0 +1,19 @@
public class Ex4 {
public static void main(String[] args) {
CurrencyConverter yenConverter = new CurrencyConverter(115.7, 0.0005);
CurrencyConverter euroConverter = new CurrencyConverter(0.9881, 0.0003);
yenConverter.setLargeAmount(50000);
euroConverter.setLargeAmount(50000);
int yens = 1500000;
System.out.println(yens + " yens = US$ " + yenConverter.toUSDollar(yens));
int usd = 20000;
System.out.println("US$ " + usd + " = " + yenConverter.fromUSDollar(usd) + " yens");
int euros = 170000;
System.out.println(euros + " euros = US$ " + euroConverter.toUSDollar(euros));
usd = 20000;
System.out.println("US$ " + usd + " = " + euroConverter.fromUSDollar(usd) + " euros");
}
}