Question
in C#, Define an abstract base class named BankAccount. Use the BankAccount class to derive a SavingsAccount and CheckingAcount class with different rules for withdrawing
in C#, Define an abstract base class named BankAccount. Use the BankAccount class to derive a SavingsAccount and CheckingAcount class with different rules for withdrawing funds. Create a new console-base project (CS3) and use the driver program provided below to test your class definitions. Name the classes as suggested so it will work with the provided test program. The classes can be defined in the program file (CS3.cs) before the Program class, so additional class files are not necessary. BankAccount: Define BankAccount as an abstract class. Declare a decimal variable to store the account balance. Should be defined as protected to allow for inheritance. Define an empty default constructor. Define an overloaded constructor with a parameter of the type decimal, which will be used to pass an amount for the initial account balance. Assign the parameter amount to the class balance variable using the property's set method (Balance = decBalance). Define a property named Balance that sets and gets the current balance (type decimal). Define a void method named deposit with a parameter of the type decimal which will be the amount of the deposit. Assume all values are positive, so the amount does NOT need to be validated. Add the amount to Balance (property name). Define an abstract method that with a return type of int named withdraw with a parameter of the type decimal which will be the amount of the withdrawal. This is an abstract method so it will not have a body, not even the open and closes braces. The implementation will be defined by each class that is derived from this base class. In the implementations, the methods will return an integer. A zero is returned if the withdrawal was successful, or a one if the account had insufficient funds. public abstract int withdraw(decimal decAmt); SavingsAccount: Declare a private decimal variable to store the rate for the withdrawal fee. The fee is 10% (.10) of the transaction amount. Initialize the rate for the withdrawal fee to .10m at declaration. Define a default constructor with an empty body. Have it call the base constructor as part of the header declaration. Define an overloaded constructor with a parameter of the type decimal, which will be used to pass an amount for the initial account balance. As part of the method header, call the overloaded constructor defined in the base class to assign the amount to the class balance variable. Define a method named withdraw to override the abstract method defined in the base class. It should have a parameter of the type decimal which will be the amount of the withdrawal. Before processing the transaction, calculate the withdrawal fee and add it to the transaction amount, and then verify there are sufficient funds in the account for the total transaction. The method should return an integer. A zero is returned if the withdrawal was successful, or a one if the account had insufficient funds. The provided transfer method will check the returned value. The function header should look something like this: public override int withdraw(decimal decAmt) CheckingAccount: Declare a private integer variable to store the number of withdrawals. Initialize the number of withdrawals to zero at declaration. The first two withdrawals are free. For all others, there is $1.50 fee. Define a default constructor with an empty body. Have it call the base constructor as part of the header declaration. Define an overloaded constructor with a parameter of the type decimal, which will be used to pass an amount for the initial account balance. As part of the method header, call the overloaded constructor defined in the base class to assign the amount to the class balance variable. Define a method named withdraw to override the abstract method defined in the base class. It should have a parameter of the type decimal which will be the amount of the withdrawal. If is the transaction count is => 2, add the transaction fee to the withdrawal amount. If there are sufficient funds in the account to withdraw the entire amount, subtract the amount from the balance and increment the withdrawal counter. The method should return an integer. A zero is returned if the withdrawal was successful, or a one if the account had insufficient funds. The provided transfer method will check the returned value. The function header should look something like this: public override int withdraw(decimal decAmt)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started