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();...
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].
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...
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...
1-Create a new Visual C# Console App (.NET Framework). Name the solution "GPA Calculation". 2-Zip and...
1-Create a new Visual C# Console App (.NET Framework). Name the solution "GPA Calculation". 2-Zip and Submit your entire project with the solution file GPA Ask the user to input their grade percentage (e.g. the use will enter 98 if they had an overall grade of 98% in their course) for their Accounting, Marketing, Economics and MIS courses. Assume each course is worth 3 credit hours. Once you have all of their grades output what letter grade they earned for...
write a c# console application app that reads all the services in the task manager and...
write a c# console application app that reads all the services in the task manager and automatically saves what was read in a Notepad txt file.  Please make sure that this program runs, also add some comments
~~~USING C# ONLY~~~ Create a console application Design a class named Person with properties for holding...
~~~USING C# ONLY~~~ Create a console application Design a class named Person with properties for holding a person’s name, address, and telephone number. Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT