Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROGRAMMING ASSIGNMENT 6 INSTRUCTIONS Adapted from: Deitel & Deitel (2017). Visual C# 2015 How to Program (6th ed.). Pearson Education, Inc. Create an inheritance hierarchy

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

PROGRAMMING ASSIGNMENT 6 INSTRUCTIONS Adapted from: Deitel & Deitel (2017). Visual C# 2015 How to Program (6th ed.). Pearson Education, Inc. 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 from class Account. Base class Account should include the following private instance variables: Balance, which is of type decimal to represent the account balance; AccountName, which is of type string and represents the account holder's last name; and Account Number, which is an integer type that represents the account's number. The class should provide a constructor that receives an account's name, account number, and an initial balance. It should use initialize these instance variables using the appropriate mutator methods (i.e. setAccountName, setAccount Number, and setBalance). The setBalance method should validate the initial balance to ensure that it's greater than or equal to 0.0; if not, set the balance to 0. You should also include the appropriate accessor (i.e. "get") methods. Also, the class should provide two other 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 print the message "Insufficient Funds." Base class Account should also have a method called PrintAccount that prints the account's name, number, and balance. called PrintAccount that prints the account's name, number, and balance. Derived class Savings Account should inherit the functionality of an Account, but also include a decimal instance variable indicating the interest rate (double) assigned to the Account. Call this variable InterestRate. Savings Account's constructor should receive the account's name, account number, initial balance, and an initial value for the interest rate. The constructor should call the base class constructor to initialize the account's name, number, and balance. It should also call a method in its own class, setInterestRate, which should set the InterestRate variable and validate that the rate is a positive number. If the interest rate passed in is negative, set the interest rate to zero. SavingsAccount should provide public method CalculateInterest that takes no arguments and returns a decimal indicating 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 modifying them.] Finally, create a method in this derived class that overrides the PrintAccount method in the base class. In it, call the base class method to print out the account's name, number, and balance, and include code in the derived class's method to print out the information specific to the derived class (i.e. InterestRate). Derived class Checking Account should inherit from base class Account and include a decimal instance variable that represents the fee charged per transaction. Call this variable FeeCharged. CheckingAccount's constructor should receive the account's name, account number, initial balance, as Page 1 of 3 well as a parameter indicating a fee amount. Create a mutator method, setFeeAmount, and call it from the constructor. If the fee amount is negative, the setFeeAmount should set it to zero. Class Checking Account should redefine methods Credit and Debit so that they subtract the fee from the account balance whenever either transaction is performed successfully. CheckingAccount's versions of these methods should invoke the base-class Account 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.] Finally, create a method in this derived class that overrides the PrintAccount method in the base class. In it, call the base class method to print out the account's name, number, and balance, and include code in the derived class's method to print out the information specific to the derived class (.e. FeeCharged). After defining the classes in this hierarchy, write an application that creates one object of each derived class and tests their methods. Add interest to the SavingsAccount object by first invoking its Calculatelnterest method, then passing the returned interest amount to the object's Credit method. The order of events should be performed as follows: 1. Create a new checking account object. Assign it an initial balance of $1,000. The account name should be your last name concatenated with the word "Checking", and the account number should be 1. The fee charged should be 3.00. Print a description of this transaction (i.e. "Created checking account with $1,000 balance.") Create a new savings account object. Assign it an initial balance of $2,000. The account name should be your last name concatenated with the work "Savings", and the account number should be your last name concatenated with the work "Savings", and the account number should be 2. The interest rate should be 5%. Print a description of this transaction (i.e. "Created savings account with $2,000 balance.") 3. Print the checking account object's information. 4. Print the savings account object's information 5. Deposit $100 in the checking account and print a description of this transaction (i.e. "Deposit $100 into checking.") (this should generate a fee charged as well) 6. Print the checking account object's information 7. Withdraw $50 from the checking account and print a description of this transaction (i.e. "Withdraw $50 from checking.") (this should generate a fee charged as well) 8. Print the checking account object's information 9. Try to withdraw $6,000 from the checking account and print a description of this transaction (i.e. "Withdraw $6,000 from checking.") (This should not generate a fee but instead produce an error message that the user has Insufficient Funds. The balance should remain unchanged.) 10. Print the savings account object's information 11. Deposit $3,000 in the savings account and print a description of this transaction (i.e. "Deposit $3,000 into savings.") 12. Print the savings account object's information 13. Withdraw $200 from the savings account and print a description of this transaction (i.e. "Withdraw $200 from savings.") 14. Print the savings account object's information 15. Calculate the interest on the savings account and print a description of this transaction (i.e. "Calculate Interest on savings.") 16. Print the savings account object's information 17. Try to withdraw $10,000 from the savings account (This should produce the insufficient Funds error message and leave the balance unchanged.) Print a description of this transaction (i.e. "Withdraw $10,000 from savings.") 18. Print the savings account object's information C.S.file:///C:/209 C# Programming/Programming Assignments/Module 5/Assignment_5_Solution/Assignment_... - 6 X Account Name: Bolt-Checking Account Number: 1 Balance: $1,000.00 Fee charged: $3.00 Account Name: Bolt-Savings Account Number: 2 Balance: $2,000.00 Interest rate : 5% Deposit $100 into checking. Account Name: Bolt-Checking Account Number: 1 Balance: $1,097.00 Fee charged: $3.00 Withdraw $50 from checking. Account Name: Bolt-Checking Account Number: 1 Balance: $1,044.00 Fee charged: $3.00 Withdraw $6,000 from checking. Insufficient funds Account Name: Bolt-Checking Account Number: 1 Balance: $1,044.00 Fee charged: $3.00 Deposit $3,000 into savings. Insufficient funds Account Name: Bolt-Checking Account Number: 1 Balance: $1,044.00 Fee charged: $3.00 Deposit $3,000 into savings. Account Name: Bolt-Savings Account Number: 2 Balance: $5,000.00 Interest rate: 5% Withdraw $200 from savings. Account Name: Bolt-Savings Account Number: 2 Balance: $4,800.00 Interest rate : 5% Calculate Interest on savings. Account Name: Bolt-Savings Account Number: 2 Balance: $5,040.00 Interest rate : 5x Withdraw $10.000 from savings. Insufficient funds Account Name: Bolt-Savings Account Number: 2 Balance: $5,040.00 Interest rate : 5% Press the [Enter) key to continue. PROGRAMMING ASSIGNMENT 6 INSTRUCTIONS Adapted from: Deitel & Deitel (2017). Visual C# 2015 How to Program (6th ed.). Pearson Education, Inc. 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 from class Account. Base class Account should include the following private instance variables: Balance, which is of type decimal to represent the account balance; AccountName, which is of type string and represents the account holder's last name; and Account Number, which is an integer type that represents the account's number. The class should provide a constructor that receives an account's name, account number, and an initial balance. It should use initialize these instance variables using the appropriate mutator methods (i.e. setAccountName, setAccount Number, and setBalance). The setBalance method should validate the initial balance to ensure that it's greater than or equal to 0.0; if not, set the balance to 0. You should also include the appropriate accessor (i.e. "get") methods. Also, the class should provide two other 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 print the message "Insufficient Funds." Base class Account should also have a method called PrintAccount that prints the account's name, number, and balance. called PrintAccount that prints the account's name, number, and balance. Derived class Savings Account should inherit the functionality of an Account, but also include a decimal instance variable indicating the interest rate (double) assigned to the Account. Call this variable InterestRate. Savings Account's constructor should receive the account's name, account number, initial balance, and an initial value for the interest rate. The constructor should call the base class constructor to initialize the account's name, number, and balance. It should also call a method in its own class, setInterestRate, which should set the InterestRate variable and validate that the rate is a positive number. If the interest rate passed in is negative, set the interest rate to zero. SavingsAccount should provide public method CalculateInterest that takes no arguments and returns a decimal indicating 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 modifying them.] Finally, create a method in this derived class that overrides the PrintAccount method in the base class. In it, call the base class method to print out the account's name, number, and balance, and include code in the derived class's method to print out the information specific to the derived class (i.e. InterestRate). Derived class Checking Account should inherit from base class Account and include a decimal instance variable that represents the fee charged per transaction. Call this variable FeeCharged. CheckingAccount's constructor should receive the account's name, account number, initial balance, as Page 1 of 3 well as a parameter indicating a fee amount. Create a mutator method, setFeeAmount, and call it from the constructor. If the fee amount is negative, the setFeeAmount should set it to zero. Class Checking Account should redefine methods Credit and Debit so that they subtract the fee from the account balance whenever either transaction is performed successfully. CheckingAccount's versions of these methods should invoke the base-class Account 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.] Finally, create a method in this derived class that overrides the PrintAccount method in the base class. In it, call the base class method to print out the account's name, number, and balance, and include code in the derived class's method to print out the information specific to the derived class (.e. FeeCharged). After defining the classes in this hierarchy, write an application that creates one object of each derived class and tests their methods. Add interest to the SavingsAccount object by first invoking its Calculatelnterest method, then passing the returned interest amount to the object's Credit method. The order of events should be performed as follows: 1. Create a new checking account object. Assign it an initial balance of $1,000. The account name should be your last name concatenated with the word "Checking", and the account number should be 1. The fee charged should be 3.00. Print a description of this transaction (i.e. "Created checking account with $1,000 balance.") Create a new savings account object. Assign it an initial balance of $2,000. The account name should be your last name concatenated with the work "Savings", and the account number should be your last name concatenated with the work "Savings", and the account number should be 2. The interest rate should be 5%. Print a description of this transaction (i.e. "Created savings account with $2,000 balance.") 3. Print the checking account object's information. 4. Print the savings account object's information 5. Deposit $100 in the checking account and print a description of this transaction (i.e. "Deposit $100 into checking.") (this should generate a fee charged as well) 6. Print the checking account object's information 7. Withdraw $50 from the checking account and print a description of this transaction (i.e. "Withdraw $50 from checking.") (this should generate a fee charged as well) 8. Print the checking account object's information 9. Try to withdraw $6,000 from the checking account and print a description of this transaction (i.e. "Withdraw $6,000 from checking.") (This should not generate a fee but instead produce an error message that the user has Insufficient Funds. The balance should remain unchanged.) 10. Print the savings account object's information 11. Deposit $3,000 in the savings account and print a description of this transaction (i.e. "Deposit $3,000 into savings.") 12. Print the savings account object's information 13. Withdraw $200 from the savings account and print a description of this transaction (i.e. "Withdraw $200 from savings.") 14. Print the savings account object's information 15. Calculate the interest on the savings account and print a description of this transaction (i.e. "Calculate Interest on savings.") 16. Print the savings account object's information 17. Try to withdraw $10,000 from the savings account (This should produce the insufficient Funds error message and leave the balance unchanged.) Print a description of this transaction (i.e. "Withdraw $10,000 from savings.") 18. Print the savings account object's information C.S.file:///C:/209 C# Programming/Programming Assignments/Module 5/Assignment_5_Solution/Assignment_... - 6 X Account Name: Bolt-Checking Account Number: 1 Balance: $1,000.00 Fee charged: $3.00 Account Name: Bolt-Savings Account Number: 2 Balance: $2,000.00 Interest rate : 5% Deposit $100 into checking. Account Name: Bolt-Checking Account Number: 1 Balance: $1,097.00 Fee charged: $3.00 Withdraw $50 from checking. Account Name: Bolt-Checking Account Number: 1 Balance: $1,044.00 Fee charged: $3.00 Withdraw $6,000 from checking. Insufficient funds Account Name: Bolt-Checking Account Number: 1 Balance: $1,044.00 Fee charged: $3.00 Deposit $3,000 into savings. Insufficient funds Account Name: Bolt-Checking Account Number: 1 Balance: $1,044.00 Fee charged: $3.00 Deposit $3,000 into savings. Account Name: Bolt-Savings Account Number: 2 Balance: $5,000.00 Interest rate: 5% Withdraw $200 from savings. Account Name: Bolt-Savings Account Number: 2 Balance: $4,800.00 Interest rate : 5% Calculate Interest on savings. Account Name: Bolt-Savings Account Number: 2 Balance: $5,040.00 Interest rate : 5x Withdraw $10.000 from savings. Insufficient funds Account Name: Bolt-Savings Account Number: 2 Balance: $5,040.00 Interest rate : 5% Press the [Enter) key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions