0
我試圖使當前餘額方法更新其餘額後撤出方法被調用,以便它成爲任何後續withdraw.I我不知道我在做什麼錯誤的起始餘額。謝謝。更新atm餘額
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
public class Customer
{
private double deposit;
private double balance;
static double bankCharge = 0.50;
public Customer(double depo)
{
if (depo > 2000)
{
Console.WriteLine("deposit cannot be morethan 2000");
}
else
{
this.deposit += depo;
}
}
public void setDeposit(double depo)
{
if (depo > 2000)
{
Console.WriteLine(" Sorry, you cannot deposit morethan 2000");
}
else
{
this.deposit+= depo;
}
}
public double currentBalance()
{
this.balance= this.deposit;
//this.balance+=this.balance;
return this.balance;
}
public double Withdrawal()
{
int amount;
bool passed;
do
{
Console.WriteLine("How much do you want to withdraw?");
passed = int.TryParse(Console.ReadLine(), out amount);
if ((!passed) || (amount % 5 != 0))
{
Console.WriteLine("Wrong input,No decimals please,Enter in multiples of 5, Try again");
}
} while (!passed || amount % 5 != 0);
double charges = amount + bankCharge; // amount to be withdrawn + the bank charge
Console.WriteLine("charges are {0}", charges);
// Console.WriteLine("Your current balance is {0}", this.currentBalance());
if (charges > this.currentBalance())
{
Console.WriteLine("Sorry, you do not have enough money to perform this transaction");
}
else
{
Console.WriteLine("Your current balance is {0}", this.balance);
this.balance-= charges; // withdrawal done
Console.WriteLine(" balance after transaction/charges is={0} ",this.balance);
}
return this.balance;
}
}
class Program
{
static void Main()
{
Customer lee = new Customer(500);
lee.setDeposit(2000);
lee.setDeposit(400);
//Console.WriteLine("the withdraw function returns this amount {0}", lee.Withdrawal());
Console.WriteLine(lee.Withdrawal());
Console.WriteLine(lee.currentBalance());
}
}
好吧,我們也不知道你在做什麼錯,因爲你沒有告訴我們你不喜歡的事情。 –
在Main中可以看到,當前餘額爲2900.可以說我想撤回40,撤回後撤回方法返回2859.5,這是正確的,因爲0.50銀行費用。問題是:當我再次調用取款功能而不是從2859.5開始的當前餘額時,它從2900開始。換句話說,我希望每次客戶調用取款方法時,起始餘額應該是返回的餘額通過最後一筆交易的提款方式。 – gasperino
請勿在評論區域包含實質細節。修改你的問題,明確你的問題。目前,還不清楚你的問題出了什麼問題,它可能會被關閉。 –