Answer to Question #189375 in C# for CHANDRASENA REDDY

Question #189375

There is a Change request from the customer. It is as follows: You need to calculate Interest paid by banks on Saving Account.


Task 1 : Add a function declaration “void CalculateInterest()” in the interface. Define the functions in the concrete classes such as ICICI accounts get 7% interest and HSBC gives 5% interest.


1
Expert's answer
2021-05-10T13:08:23-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace C_SHARP
{
    class Program
    {


        interface IInterest
        {
            void CalculateInterest();
        }
        class SavingsAccount
        {
            private double annualInterestRate = 0.0; 
            private double savingsBalance;


            public SavingsAccount(double initBalance)
            {
                savingsBalance = initBalance;
            }


            public double getBalance() { return savingsBalance; }


        
            public double getInterestRate()
            {
                return annualInterestRate;
            }
        }


        class ICICI: SavingsAccount, IInterest
        {
            //concrete classes such as ICICI accounts get 7% 
            private double annualInterestRate = 7.0;


            public ICICI(double initBalance):base(initBalance)
            {
                
            }
            public void CalculateInterest()
            {
                double savingsBalance=getBalance();
                savingsBalance *= (1 + (annualInterestRate / 100 / 12));
                Console.WriteLine("Saving balance for ICICI account: {0}", savingsBalance.ToString("C"));
            }
        }
        class HSBC  : SavingsAccount, IInterest
        {
            //SBC gives 5% interest.
            private double annualInterestRate = 5.0;


            public HSBC(double initBalance)
                : base(initBalance)
            {


            }
            public void CalculateInterest()
            {
                double savingsBalance = getBalance();
                savingsBalance *= (1 + (annualInterestRate / 100 / 12));
                Console.WriteLine("Saving balance for HSBC account: {0}", savingsBalance.ToString("C"));
            }
        }




        static void Main(string[] args)
        {


            
            IInterest savingsAccountICICI = new ICICI(5000);
            savingsAccountICICI.CalculateInterest();
            IInterest savingsAccountHSBC = new HSBC(5000);
            savingsAccountHSBC.CalculateInterest();




            Console.ReadKey();


        }
    }
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS