我在項目的這一部分遇到問題。基本的想法是將程序作爲具有提款金額的用戶,然後更新總餘額。我試圖用switch語句來做到這一點。我不知道如何使用,同時保持具體的數據類型布爾用於java貨幣兌換的withdraw()方法
public static boolean withdraw(double amount, int currencyType) {
double withdrawAmount = 0;
switch (currencyType){
case 1: withdrawAmount = balance - amount;
}
updateBalance(getBalance() + convertCurrency(amount, currencyType, true));
System.out.print(withdrawAmount);
return false;
//TODO: implementation here
}
//my deposit method//
public static boolean deposit(double amount, int currencyType) {
if(amount <= 0){
return false;
}
String currency = "";
switch (currencyType){
case 1: currency = "U.S. Dollars"; break;
case 2: currency = "Euros"; break;
case 3: currency = "British Pounds"; break;
case 4: currency = "Indian Rupees"; break;
case 5: currency = "Australian Dollars"; break;
case 6: currency = "Canadian Dollars"; break;
case 7: currency = "Singapore Dollars"; break;
case 8: currency = "Swiss Francs"; break;
case 9: currency = "Malaysian Ringgits"; break;
case 10: currency = "Japanese Yen"; break;
case 11: currency = "Chinese Yuan Renminbi"; break;
default: return false;
}
updateBalance(getBalance() + convertCurrency(amount, currencyType, true));
System.out.println("You successfully deposited " + amount + " " + currency);
System.out.print("\n\n");
return true;
「while keep dataType boolean」which'dataType'?在你的數據類型的問題中沒有提到?編輯你的問題,目前還不清楚你問什麼。 –
我的意思是這個方法必須返回一個布爾值。 – Andronik
這是我如何做我的depost()方法,但即時提款退出。 – Andronik