我正在创建一个具有这两种我无法弄清楚的方法的程序。它们是“提款”和“存款”,它们位于 CheckingAccount 类中。在这些方法中,我希望最初的值为 0 然后添加到它。然后我想取新数字并从中减去。我想“存入”250 美元。然后我想“提取” 98 美元。我不确定在哪里存储这些值以及如何执行它们。当我将提款和存款方法留空时,我知道显示应该如何结束。
账户类:
class Account
{
protected string firstName;
protected string lastName;
protected long number;
public string FirstName
{
set
{
firstName = value;
}
}
public string LastName
{
set
{
lastName = value;
}
}
public long Number
{
set
{
number = value;
}
}
public override string ToString()
{
return firstName + " " + lastName + "\nAccount #: " + number;
}
}
}
支票账户类:
class CheckingAccount : Account
{
private decimal balance;
public CheckingAccount(string firstName, string lastName, long number, decimal initialBalance)
{
FirstName = firstName;
LastName = lastName;
Number = number;
Balance = initialBalance;
}
public decimal Balance
{
get
{
return balance;
}
set
{
balance = value;
}
}
public void deposit(decimal amount)
{
//initial value should be 0 and should be adding 250 to it.
}
public void withdraw(decimal amount)
{
//this takes the 250 amount and subtracts 98 from it
}
public void display()
{
Console.WriteLine(ToString());
Console.WriteLine("Balance: ${0}", Balance);
}
}
}
展示类:
class Display
{
static void Main(string[] args)
{
CheckingAccount check = new CheckingAccount("John", "Smith", 123456, 0M);
Console.WriteLine("After Account Creation...");
check.display();
Console.WriteLine("After Depositing $250...");
//constructor
Console.WriteLine("After Withdrawing $98...");
//constructor
}
}
}
我希望我的输出看起来像这样:
创建帐户后...
John Smith
帐户编号:123456
余额:0
存入 250 美元后...
John Smith
帐号:123456
余额:250
提取 98 美元后...
John Smith
帐号:123456
余额:152