Answer to Question #189421 in C# for CHANDRASENA REDDY

Question #189421

Lab-11

Q1. ICICI Bank want’s to implement SMS alert fascility to the customers whenever they pay the Credit Card Bill. The CreditCard class contains the following fields.

CreditCardNo, CardHolderName, BalanceAmount, CreditLimit.


The class has three functions. GetBalance(), GetCreditLimit(), and MakePayment(). Whenever the MakePayment() method is called, it should update the BalanceAmount and raise an event. The event should send a message. ( You don’t need to write a logic to send the sms. Only print the message saying amount is credited.)


Task to be performed:

Define a class CreditCard

Define a Delegate to Handle the Event

Define an event which will be raised whenever the payment is made.

Create a Console client application, and try the functionality.


1
Expert's answer
2021-05-15T07:31:37-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Threading;


namespace C_SHARP
{
    class Program
    {
        ///Define a Delegate to Handle the Event
        public delegate void SendSMS(string message);


        public class CreditCard
        {
            //The CreditCard class contains the following fields. 
            //CreditCardNo, CardHolderName, BalanceAmount, CreditLimit.


            private string creditCardNo;
            private string cardHolderName;
            private double balanceAmount;
            private double creditLimit;


            /// <summary>
            /// COnstructor
            /// </summary>
            /// <param name="creditCardNo"></param>
            /// <param name="cardHolderName"></param>
            /// <param name="balanceAmount"></param>
            /// <param name="creditLimit"></param>
            public CreditCard(string creditCardNo, string cardHolderName, double balanceAmount, double creditLimit)
            {
                this.creditCardNo = creditCardNo;
                this.cardHolderName = cardHolderName;
                this.balanceAmount = balanceAmount;
                this.creditLimit = creditLimit;
            }




            public double GetBalance()
            {
                return balanceAmount;
            }


            public double GetCreditLimit()
            {
                return creditLimit;
            }


            /// <summary>
            /// Whenever the MakePayment() method is called, it should update the BalanceAmount and raise an event.
            /// </summary>
            /// <param name="amount"></param>
            public void MakePayment(double amount)
            {
                if (paymentIsMade != null)
                {
                    if (amount <= creditLimit)
                    {
                        this.balanceAmount -= amount;
                        paymentIsMade(string.Format("{0} has made payment for amount {1}. The balance is {2} now", this.cardHolderName, amount, this.balanceAmount));
                    }
                    else
                    {
                        paymentIsMade(string.Format("The customer wiht credit card no {0} has a credit limit {1}!", this.creditCardNo, creditLimit));
                    }
                }


            }


            //Define an event which will be raised whenever the payment is made.
            public event SendSMS paymentIsMade;


        }
        /// <summary>
        /// The start point of the program
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            //Create a Console client application, and try the functionality.
            CreditCard creditCard = new CreditCard("4654654131", "Mary Clark", 1000, 500);
            creditCard.paymentIsMade += ShowSMS;
            creditCard.MakePayment(100);
            creditCard.MakePayment(1000);


            Console.ReadLine();


        }
        /// <summary>
        /// Show SMS
        /// </summary>
        /// <param name="message"></param>
        static void ShowSMS(string message)
        {
            Console.WriteLine(message);
        }
    }
}

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
APPROVED BY CLIENTS