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();...
Create a console app with C# that uses a while loop to calculate the average of...
Create a console app with C# that uses a while loop to calculate the average of 3 test scores. Input integers, but use the appropriate average data type. Generally, you use a while to do something while a condition is true. You can use a while loop to execute a certain number of times. *While* this is not the best use of the while loop and another loop is generally more appropriate, it follows the pattern below set a counter...
Create a console app c#. Using a List, ask the user to enter all of their...
Create a console app c#. Using a List, ask the user to enter all of their favorite things. Once they are done, randomly pick a value from the list and display it.
IN C# lang Write a console app (review Module 5 for console app) that stores 3...
IN C# lang Write a console app (review Module 5 for console app) that stores 3 students test stores in 3 separate arrays as integers. Some did not not take all the tests, so they each have a their own length and we use separate arrays. Declare and initialize each array. Use meaningful names. Print each array as follows: Morgan 98, 72, 65 Bowie 15, 47, 35, 92, 94 Ananya 91, 68, 87, 75 Extra credit: Compute the average for...
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].
In C# using a Console App, create an array that stores 20 integer values. Use the...
In C# using a Console App, create an array that stores 20 integer values. Use the random number generator to select an integer value between 0 and 10. Store the 20 random integers in the array. Once the array has been created: Print the values in the array. Print the values in the array in reverse order. Sort and print the values in the array in ascending order. Sort and print the values in the array in descending order. Count...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
Shopping Cart App (C#) Please create a C# Console (.NET Framework) application which reads from the...
Shopping Cart App (C#) Please create a C# Console (.NET Framework) application which reads from the user, the price of items in their shopping "cart". Be sure to tell the user how to stop (or ask them if they want to stop) entering prices. Items can be priced any positive number greater than zero. When the user has entered the prices for all items in their "cart", calculate the subtotal (the sum of all item prices). Next, check if the...
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...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT