Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Must be Written in C#. I need an Account Inheritence Class that displays the output below This is what I have for the Hierarchy Class

Must be Written in C#. I need an Account Inheritence Class that displays the output below

image text in transcribed

This is what I have for the Hierarchy Class

using System; public class Account { private decimal balance; public Account(decimal b) { Balance = b; } public decimal Balance { get { return balance; } set { if (value > 0) balance = value; else throw new ArgumentOutOfRangeException("Balance", value, "Balance should be greater than 0"); } } public virtual bool Debit(decimal amount) { if ((Balance - amount) > 0) { Balance -= amount; return true; } else { Console.WriteLine("Debit Amount exceeded Account Balance"); return false; } } public virtual void Credit(decimal amount) { Balance += amount; } } public class SavingsAccount : Account { private decimal interestrate; public SavingsAccount(decimal b, decimal ir) : base(b) { interestrate = ir; } public decimal InterestRate { get { return interestrate; } } public decimal CalculateInterest() { return Balance * interestrate; } } public class CheckingAccount : Account { public CheckingAccount(decimal b, decimal f) : base(b) { fee = f; } public decimal Fee { get { return Fee; } } public override bool Debit(decimal amount) { if (base.Debit(amount)) { base.Debit(fee); return true; } else { return false; } } public override void Credit(decimal amount) { base.Credit(amount); base.Debit(fee); } } public class AccountTest { public static void Main(string[] args) { bool success; Account a1 = new Account(5500.00M); Console.WriteLine("Account object a1 has balance= {0} ", a1.Balance); Console.WriteLine("Trying to set balance = -1000 for account a1"); try { a1.Balance = -1000.00M; } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(ex.Message + " "); } SavingsAccount s1 = new SavingsAccount(5000.00M, 0.10M); Console.WriteLine("Account object s1 has balance= {0} Interest Rate = {1}", s1.Balance, s1.InterestRate); decimal interest = s1.CalculateInterest(); Console.WriteLine("Interest for s1 = {0}", interest); s1.Credit(interest); Console.WriteLine("Balance in s1 after crediting interest = {0}", s1.Balance); success = s1.Debit(4000.00M); Console.WriteLine("Balance in s1 after debiting 4000 = {0}", s1.Balance); Console.WriteLine("Trying to debit 3000 from s1"); success = s1.Debit(3000.00M); Console.WriteLine("Balance in s1 = {0} ", s1.Balance); CheckingAccount c1 = new CheckingAccount(3000.00M, 100.00M) Console.WriteLine("Account object c1 has balance= {0} Transaction Fee = {1}", c1.Balance, c1.Fee); success = c1.Debit(2000.00M); Console.WriteLine("Balance in c1 after debiting 2000 = {0}", c1.Balance); Console.WriteLine("Trying to debit 4000 from c1"); success = c1.Debit(4000); Console.WriteLine("Balance in c1 = {0}", c1.Balance); c1.Credit(3000.00M); Console.WriteLine("Balance in c1 after crediting 3000 = {0}", c1.Balance); Console.ReadLine(); } }

pm Assignment 05 Due Date: 02/26/2020 12:00 Total points: 15 Work on Exercise 11.9 from Ch 11 (Account Inheritance Hierarchy). Create console app "Account Hierarchy" to work on this assignment. Expected output for positive scenario: account1 balance: $50.00 account balance: $25.00 account3 balance: $80.00 Attempting to debit accounti by $25.00. accounti balance: $25.00 Attempting to debit account2 by $30.08. Debit amount exceeded account balance. account balance: $25.00 Attempting to debit account 3 by $40.08. $1.00 transaction fee charged. account balance: $39.00 Credit ing $40.90 to accounti. account balance: $65.00 Crediting $65.00 to account2. account balance: $90.00 Credit ing $20.80 to account3. $1.00 transaction fee charged. account balance: $58.00 Adding $2.79 interest to account2. New account balance: $92.29

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions