为什么初始余额不显示在主要的checkaccount? [英] Why isn't the initial balance showing in the main for checkingaccount?
本文介绍了为什么初始余额不显示在主要的checkaccount?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assignment5
{
class Program
{
class BankAccount
{
private double balance;
public BankAccount() { balance = 0.0; }
public BankAccount(double iA)
{
balance = iA;
}
public virtual double Withdraw(double a)
{
if (balance >= a)
{
balance -= a;
return balance;
}
else
return -1.0;
}
public void Deposit(double a)
{
balance += a;
}
public double GetBalance() { return balance; }
public class CheckingAccount : BankAccount
{
private double minBalance, charge;
public CheckingAccount(double minA, double charge) : base()
{
minBalance = minA;
this.charge = charge;
}
public double ProcessCheck(double a)
{
double r;
if (GetBalance() >= minBalance)
r = base.Withdraw(a);
else
r = base.Withdraw(a + charge);
return 0.0;
}
public override double Withdraw(double a)
{
return ProcessCheck(a);
}
}
double x, y;
public class SavingsAccount : BankAccount
{
private double ir;
public SavingsAccount(double a, double r) : base(a)
{
ir = r;
}
public void PostInterest()
{
double balance = GetBalance();
double interest = balance * ir / 100;
Deposit(interest);
}
}
static void Main(string[] args)
{
CheckingAccount ca = new CheckingAccount(2000.0, 2.0);
Console.WriteLine("The initial balance is {0:c}", ca.GetBalance());
ca.Deposit(1000.0);
Console.WriteLine("Current balance after the deposit is {0:c}", ca.GetBalance());
ca.ProcessCheck(300.0);
Console.WriteLine("The balance after ProcessCheck is {0:c}", ca.GetBalance());
ca.Withdraw(500.0);
Console.WriteLine("The balance after withdrawl is {0:c}", ca.GetBalance());
CheckingAccount x = new CheckingAccount(2000.0, 2.0);
Console.WriteLine("The balance of x is {0:c}", x.GetBalance());
x.Deposit(1000.0);
Console.WriteLine("The balance after deposit is {0:c}", x.GetBalance());
x.Withdraw(500.0);
Console.WriteLine("The balance after withdrawl is {0:c}", x.GetBalance());
SavingsAccount y = new SavingsAccount(4000.0, 5.0);
Console.WriteLine("The balance of y is {0:c}", y.GetBalance());
y.Deposit(1000.0);
Console.WriteLine("The balance after the deposit is {0:c}", y.GetBalance());
y.Withdraw(500.0);
Console.WriteLine("The balance after withdrawl is {0:c}", y.GetBalance());
}
}
}
}
我尝试了什么:
我已经尝试过并完成了所有事情。我在CheckingAccount ca和CheckingAccount x主要面临的唯一问题是,当我运行程序时,它没有显示我的初始余额2000.0,2.0。你能帮我吗?
作业如下。
What I have tried:
I've tried and completed everything. The only problem I'm facing in the main for "CheckingAccount ca" and "CheckingAccount x", it's not showing my initial balance of 2000.0, 2.0 when I run the program. Can you help?
The assignment is below.
using System;
namespace A5a_YourLastName
{
public class BankAccount {…}//this is the example 5.1 with the virtual keyword in Withdraw
// method declaration (see Fig. 10.2 on Page 386)
public class ChecingAccount {…} //this is the example 10.7
public class QuizEx10_7
{
public static void Main()
{
//a) Declare a local variable ca of type CheckingAccount,
// Creat a ChecingAccount object with two arguments 2000.0 and 2.0,
// assign the object to the variable ca and output the balance of ca.
//b) Deposit 1000.0 dallors to the CheckingAccount ca and output the balance of ca.
//c) Through the CheckingAccount ca process a check with $300 and output the balance of ca.
//d) Withdraw 500.0 dallors from the CheckingAccount ca and output the balance of ca.
} //end of Main
}//end of class
}//end of namespace
写上面Main方法的输出:
Write the output from the above Main method:
using System;
namespace A5b_YourLastName
{
public class BankAccount {…} //this is the example 5.1 with the virtual keyword in Withdraw
// method declaration (see Fig. 10.2 on Page 386)
public class SavingsAccount {…} //this is the example 10.5
public class ChecingAccount {…} //this is the example 10.7
public class QuizEx10_11
{
public static void Main()
{
//a) Declare two local variables x and y of type BankAccount
//b) Creat a ChecingAccount object with two arguments 2000.0 and 2.0,
// assign the object to the variable x and output the balance of x.
//c) Creat a SavingsAccount object with two arguments 4000.0 and 5.0,
// assign the object to the variable y and output the balance of y.
//d) Deposit 1000.0 dallors to each account of x and y, and output the balance of each account.
//d) Withdraw 500.0 dallors from each account, and output the balance of each account.
推荐答案
300并输出余额ca。
// d)从CheckingAccount ca中提取500.0 dallors并输出ca的余额。
} // 主要结束
} // 课程结束
} // 命名空间结束
300 and output the balance of ca. //d) Withdraw 500.0 dallors from the CheckingAccount ca and output the balance of ca. } //end of Main }//end of class }//end of namespace
写出输出以上主要方法:
Write the output from the above Main method:
using System;
namespace A5b_YourLastName
{
public class BankAccount {…} //this is the example 5.1 with the virtual keyword in Withdraw
// method declaration (see Fig. 10.2 on Page 386)
public class SavingsAccount {…} //this is the example 10.5
public class ChecingAccount {…} //this is the example 10.7
public class QuizEx10_11
{
public static void Main()
{
//a) Declare two local variables x and y of type BankAccount
//b) Creat a ChecingAccount object with two arguments 2000.0 and 2.0,
// assign the object to the variable x and output the balance of x.
//c) Creat a SavingsAccount object with two arguments 4000.0 and 5.0,
// assign the object to the variable y and output the balance of y.
//d) Deposit 1000.0 dallors to each account of x and y, and output the balance of each account.
//d) Withdraw 500.0 dallors from each account, and output the balance of each account.
在CheckingAccount的构造中,使用:
In the construction of CheckingAccount, Use:
public CheckingAccount(double minA, double charge)
: base(minA)
而不是
instead of
public CheckingAccount(double minA, double charge)
: base()
你错过了设置余额
。
这篇关于为什么初始余额不显示在主要的checkaccount?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文