Develop Visual Studio C# application for the following: An Abstract Class called Account has two inherited classes: Checking Account and Savings Account. Create constructors and ToString Methods for both accounts. Each type of account will also have a Balance and two methods: Deposit and Withdraw. Account objects should be placed in a Generic List and they should Polymorphically execute both Deposit and Withdraw methods. In the Main Method, start each account with $1000 balance. Ask users to enter one deposit for each account, and one withdrawal for each account and display the balance after each deposit and withdrawal. The application will exit after the last withdrawal.
Solution
class Program
{
static void Main(string[] args)
{
cAccout b = new cAccout(4343, \"person\", 5000);
sAccout s = new sAccout(4343, \"person\", 5000);
b.deposit(2000);
b.withdraw(5000);
b.printdetails();
Console.WriteLine(\"..................\");
Console.WriteLine(b.getBalance());
Console.WriteLine(\"..................\");
s.deposit(3000);
s.withdraw(2000);
s.printdetails();
Console.WriteLine(\"..................\");
Console.WriteLine(s.getBalance());
Console.Read();
}
}
class cAccout
{
//data members
int acno = 0;
string aname;
double balance = 0;
public double minbal = 1000;
//code members
public cAccout(int acno, string aname, double bal)
{
this.acno = acno;
this.aname = aname;
this.balance = bal;
}
public void deposit(double amt)
{
this.balance += amt;
}
public void withdraw(double amt)
{
if ((balance - minbal) >= amt)
{
this.balance -= amt;
}
else
{
Console.WriteLine(\"Please maintain minimum balance..!\");
}
}
public void printdetails()
{
Console.WriteLine(\"Checking Account\");
Console.WriteLine(acno);
Console.WriteLine(aname);
Console.WriteLine(balance);
}
public double getBalance()
{
return balance;
}
}
class sAccout
{
//data members
int acno = 0;
string aname;
double balance = 0;
public double minbal = 1000;
//code members
public sAccout(int acno, string aname, double bal)
{
this.acno = acno;
this.aname = aname;
this.balance = bal;
}
public void deposit(double amt)
{
this.balance += amt;
}
public void withdraw(double amt)
{
if ((balance - minbal) >= amt)
{
this.balance -= amt;
}
else
{
Console.WriteLine(\"Please maintain minimum balance..!\");
}
}
public void printdetails()
{
Console.WriteLine(\"Savings Account\");
Console.WriteLine(acno);
Console.WriteLine(aname);
Console.WriteLine(balance);
}
public double getBalance()
{
return balance;
}
}
.