Question

In: Computer Science

Needs to be written in C# Console App! Create a base class BankAccount. Decide what characteristics...

Needs to be written in C# Console App! Create a base class BankAccount. Decide what characteristics are common for checking and saving accounts and include these characteristics in the base class. Define derived classes for checking and savings. In your design , do not allow the banking base account to be instantiated --only the checking and saving classes. Use a Program class to test your design.

Solutions

Expert Solution

using System;

class BankAccount //base class
{
   protected int accountNumber; //protected data members can be used in derived classes
   protected double balance;
   public void deposit(double amount) //define deposit method
    {
        balance = balance + amount;
    }
  
}
class SavingAccount: BankAccount   //derived class
{
    public SavingAccount(int accountNumber,double balance) //constructor
    {
        this.accountNumber = accountNumber;
        this.balance = balance;
    }
    public void withdraw(double amount) //withdraw method
    {
        if(balance < amount)
        Console.WriteLine("Cannot be done");
        else
        balance = balance - amount;
    }
    public override string ToString()
    {
        return "Saving Account : Account number = "+accountNumber+"Balance = "+balance;
    }
  
}
class CheckingAccount : BankAccount //derived class
{
    private double overdraftLimit;
    public CheckingAccount(int accountNumber,double balance,double overdraftLimit) //constructor
    {
        this.accountNumber = accountNumber;
        this.balance = balance;
        this.overdraftLimit = overdraftLimit;
    }
  
    public void withdraw(double amount) //withdraw method checks overdraft limit also
    {
        if(balance + overdraftLimit < amount)
        Console.WriteLine("Cannot be done");
        else
        balance = balance - amount;
    }
    public override string ToString()
    {
        return "Checking Account : Account number = "+accountNumber+" Balance = "+balance;
    }
}

public class AccountTest
{
   public static void Main()
   {
       SavingAccount sa = new SavingAccount(1456,677.50);
       sa.deposit(200);
       Console.WriteLine(sa.ToString());
      
       CheckingAccount ca = new CheckingAccount(1004,677.50,200);
       sa.withdraw(1000);
       Console.WriteLine(ca.ToString());
      
   }
}


Output:

Saving Account : Account number = 1456Balance = 877.5                                                                                                  

Cannot be done                                                                                                                                         

Checking Account : Account number = 1004 Balance = 677.5


Related Solutions

using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
Find MIN. Write a C# console app consisting of class MIN with the method CalculateMin() and...
Find MIN. Write a C# console app consisting of class MIN with the method CalculateMin() and the driver class. Print the MIN and MIN's location. Don't count numbers outside the range [0, 100].
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
C# windows application form. Create a base class to store characteristics about a loan. Include customer...
C# windows application form. Create a base class to store characteristics about a loan. Include customer details in the Loan base class such as name, loan number, and amount of loan. Define subclasses of auto loan and home loan. Include unique characteristics in the derived classes. For example you might include details about the specific auto in the auto loan class and details about the home in the home loan class. Create a presentation class to test your design by...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data:  Account holder’s name (string)  Account number (int)  Account type (string, check/savings/business)  Balance (double)  Interest rate (double) – store interest rate as a decimal number.  Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. 1.2 Implement...
Create a class BankAccount to hold at least the following data / information about a bank...
Create a class BankAccount to hold at least the following data / information about a bank account: Account balance Total number of deposits Total number of withdrawals Interest rate e.g., annual rate = 0.05 Service charges per month The class should have the following member functions: Constructor To set the required data. It may be parameterized or user’s input. depositAmount A virtual function used to accept an argument for the amount to be deposited. It should add the argument (amount)...
Write a program to create a bank account and to process transactions. Call this class bankAccount...
Write a program to create a bank account and to process transactions. Call this class bankAccount A bank account can only be given an initial balance when it is instantiated. By default, a new bank account should have a balance of 0. A bank account should have a public get method, but no public set method. A bank account should have a process method with a double parameter to perform deposits and withdrawals. A negative parameter represents a withdrawal. It...
In C++, define the class bankAccount to implement the basic properties of a bank account. An...
In C++, define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 components of type bankAccount to...
C# (Tic-Tac-Toe) Create class TicTacToe that will enable you to write a complete app to play...
C# (Tic-Tac-Toe) Create class TicTacToe that will enable you to write a complete app to play the game of Tic-Tac-Toe. The class contains a private 3-by-3 rectangular array of integers. The constructor should initialize the empty board to all 0s. Allow two human players. Wherever the first player moves, place a 1 in the specified square, and place a 2 wherever the second player moves. Each move must be to an empty square. After each move, determine whether the game...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT