Question

For this week's assignment , please create an application following directions in the attached document.(windows form...

For this week's assignment , please create an application following directions in the attached document.(windows form application)

Create a base class named Account and derived classes named SavingsAccount and CheckingAccount that inherit from class Account. Base class Account should include one private instance variable of type decimal to represent the account balance. The class should provide a constructor that receives an initial balance and uses it to initialize the instance variable with a public property. The property should validate the initial balance to ensure that it’s greater than or equal to 0.0; if not throw an exception. The class should provide two public methods. Method Credit should add an amount to the current balance. Method Debit should withdraw money from the Account and ensure that the debit amount does not exceed the Account’s balance. If it does, the balance should be left unchanged, and the method should display the message “Debit amount exceeded the account balance.” The class should also provide a get accessor in property Balance that returns the current balance. Derived class SavingsAccount should inherit the functionality of an Account, but also include a decimal instance variable indicating the interest rate (percentage) assigned to the account. SavingsAccount’s constructor should receive the initial balance, as well as an initial value for the interest rate. SavingsAccount should provide public method CalculateInterest that returns a decimal that indicates the amount of interest earned by an account. Method CalculateInterest should determine this amount by multiplying the interest rate by the account balance.[ Note : SavingsAccount should inherit methods Credit and Debit without redefining them.] Derived class CheckingAccount should inherit from base class Account and include a decimal instance variable that represents the fee charged per transaction. CheckingAccount’s constructor should receive the account’s initial balance, as well as a parameter indicating a fee amount. Class CheckingAccount should redefine methods Credit and Debit so that they subtract the fee from the account balance whenever either transaction is performed successfully. CheckingAccount’s version of these methods should invoke the base-class Account version to perform the updates to an account balance. CheckingAccount’s Debit method should charge a fee only if money is actually withdrawn (i.e., the debit amount does not exceed the account balance). [Hint: Define Account’s Debit method so that it returns a bool indicating whether money was withdrawn. Then use the return value to determine whether a fee should be charged.] After defining the classes in this hierarchy, write an app that creates objects of each class and tests their methods. Add interest to the SavingsAccount object by first invoking its CalculateInterest method, then passing the returned interest amount to the object’s Credit method.

"C#"

please screenshot of the whole code. thanks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;

public class Account
{
private decimal balance; // private member balance

public Account(decimal balance) // constructor to set balance
{
Balance = balance;
}

public virtual void Credit(decimal amt) // add amount to the current balance
{
balance = amt+balance;
}

public virtual bool Debit(decimal amt)
{
if (amt <= balance) // if amount is lesser than the balance
{
balance = balance-amt;
return true; // widthraw sucessful
}
else
{
Console.WriteLine("Debit amount exceeded account balance"); // throwing message
return false;
}   
}

  
public decimal Balance // get and set of balance
{
get { return balance; }
set
{
if (value >= 0.0M) // appllying condition that it should be greater than 0.0
{
balance = value;
}
else
{
balance = 0.0M;
Console.WriteLine("Balance should be greater equal to 0.0 setting it to 0.0");
}
}
}
  
  
}


public class SavingsAccount : Account //derived class SavingsAccount from Base class Account

{
private decimal interestRate; //private instance interestRate
  
public SavingsAccount(decimal balance, decimal interestRate) : base(balance) //constructor of SavingsAccount with addition to the value for the base class Account
{
this.interestRate = interestRate;
}

public decimal CalculateInterest() // function to calculate the interestRate

{
return Balance * interestRate / 100m; //Balance is the getter setter value of the private instance balance of Account class
}
}

public class CheckingAccount : Account //derived class CheckingAccount from base class
{
private decimal fee; // private member fee of CheckingAccount class

public CheckingAccount(decimal balance, decimal fee) : base(balance) // constructor which sets inital value of fee and the base class value balance.
{
this.fee = fee;
}

public override void Credit(decimal amount) //overriding the function Credit for the derived class fee
{
base.Credit(amount); // call base class credit function
Balance = Balance-fee;
}

public override bool Debit(decimal amount) //overriding the function Debit for the derived class fee
{
if(base.Debit(amount))
{
Balance = Balance-fee;
return true;
}
else
{
return false;
}
}

}
class Application
{
static void Main()
{
Account obj = new Account(1050); //obj of account
Console.WriteLine("Account1: Initial Balance: {0:C}", obj.Balance);
obj.Credit(300);
obj.Debit(80);
Console.WriteLine("Account1: Final Balance: {0:C}", obj.Balance);
Console.WriteLine();
  
SavingsAccount obj3 = new SavingsAccount(100, 5);
Console.WriteLine("Account2: Initial Balance: {0:C}", obj3.Balance);
obj3.Credit(200);
obj3.Debit(40);
Console.WriteLine("Current Balance: {0:C}", obj3.Balance);
decimal interest = obj3.CalculateInterest();
obj3.Credit(interest);
Console.WriteLine("Account2: Final Balance: {0:C}", obj3.Balance);
Console.WriteLine();

CheckingAccount obj2 = new CheckingAccount(4400, 2.5M);
Console.WriteLine("Account3: Initial Balance: {0:C}", obj2.Balance);
obj2.Credit(200);
obj2.Debit(70);
Console.WriteLine("Account3: Final Balance: {0:C}", obj2.Balance);

Console.ReadKey();
}
}

Output Input Comments Account1: Initial Balance: $1,050.00 Account1: Final Balance: $1,270.00 Account2: Initial Balance: $100

FOR ANY QUERY PLEASE COMMENT GIVE A LIKE

Add a comment
Know the answer?
Add Answer to:
For this week's assignment , please create an application following directions in the attached document.(windows form...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e.,...

    In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e., debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction (i.e., credit or debit). Create an inheritance hierarchy containing base class Account and derived...

  • Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’...

    Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this back can deposit (i.e. credit) money into their accounts and withdraw (i.e. debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction. Create base class Account and derived classes SavingsAccount and CheckingAccount that inherit...

  • question

    : Implement the following given scenario in C++ a. Create an inheritance hierarchy by writing the source code, containing base class BankAccount and derived classes SavingsAccount and CheckingAccount that inherit from class BankAccount. b. Implement Polymorphism where required to achieve the polymorphic behavior. c. Multiple constructors be defined for initializing the account of a user. d. The class should provide four member functions. i. Member function Credit should add an amount to the current balance. ii. Member function Debit should...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes....

    Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAc-count ("CD", or certicate of deposit). Deliverables A driver program (driver.cpp) An implementation of Account class (account.h) An implementation of SavingsAccount (savingsaccount.h) An implementation of CheckingAccount (checkingaccount.h) An implementation of...

  • Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending...

    Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending monthly balances for a checking account and a savings account. --->Console Welcome to the Account application Starting Balances Checking: $1,000.00 Savings:  $1,000.00 Enter the transactions for the month Withdrawal or deposit? (w/d): w Checking or savings? (c/s): c Amount?: 500 Continue? (y/n): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y/n): n Monthly Payments and Fees Checking fee:              $1.00 Savings...

  • MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture...

    MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture an output. polymorphism. Write an application that creates a vector of Account pointers to two SavingsAccount and two CheckingAccountobjects. For each Account in the vector, allow the user to specify an amount of money to withdraw from the Account using member function debit and an amount of money to deposit into the Account using member function credit. As you process each Account, determine its...

  • Bank Accounts Look at the Account class Account.java and write a main method in a different...

    Bank Accounts Look at the Account class Account.java and write a main method in a different class to briefly experiment with some instances of the Account class. • Using the Account class as a base class, write two derived classes called SavingsAccount and CheckingAccount. A SavingsAccount object, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. A CheckingAccount object, in addition to the attributes of an...

  • code must be in java. Assignment 5 Purpose In this assignment, you will implement a class...

    code must be in java. Assignment 5 Purpose In this assignment, you will implement a class hierarchy in Java. Instructions The class hierarchy you will implement is shown below account Package Account manager Package SavingAccount CheckingAccount AccountManager The descriptions of each class and the corresponding members are provided below. Please note that the Visibility Modifiers (public, private and protected) are not specified and you must use the most appropriate modifiers Class AccountManager is a test main program. Create it so...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT