samedi 16 avril 2016

Bank Factory c#

in this Demo i have create the bank factory application and i want the form to show the user the interest rate with the amount when he write the name and amount and click saving or checking button... but am try to do and i don't know how..

here is my class's

  1. Bank Interface

namespace BankFactory { interface bank { decimal CalculateInterest(); } }

  1. Saving Class

namespace BankFactory { class Saving : bank { private string AccountNumber; private decimal Amount; private decimal interestRate;

    public Saving(string accountNumber, decimal amount, decimal interest)
    {
        accountNumber = AccountNumber;
        amount = Amount;
        interest = interestRate;
    }

    public Saving() { }
    public decimal CalculateInterest() { 
    return Amount * interestRate / 100m;
    }
    public string accountNumber
    {
        get { return AccountNumber; }
    }
    public decimal amount
    {
        get { return Amount; }
    }
    public decimal interest
    {
        get { return interestRate; }
    }

}

}

  1. Checking Account

namespace BankFactory { class Checking : bank { private string AccountNumber; private decimal Amount; private decimal interestRate;

    public Checking(string accountNumber, decimal amount, decimal interest)
    {
        accountNumber = AccountNumber;
        amount = Amount;
        interest = interestRate;
    }

    public Checking() { }
    public decimal CalculateInterest() {
        return 0;
    }
    public string accountNumber
    {
        get { return AccountNumber; }
    }
    public decimal amount
    {
        get { return Amount; }
    }
    public decimal interest
    {
        get { return interestRate; }
    }

}

}

  1. BankFactory class

namespace BankFactory { class bankfactory { public bankfactory() { } public bank getbankType(string bankType) { if (bankType.ToLower() == "Saving") return new Saving(); else if (bankType.ToLower() == "Checking") return new Checking(); else return null; } }

}


here the 2 buttons code

    private void btnSaving_Click(object sender, EventArgs e)
    {
        bankfactory s = new bankfactory();
        Saving sa = (Saving)s.getbankType("Saving");
        btnInterest.Text = sa.CalculateInterest().ToString();
        MessageBox.Show(sa.CalculateInterest().ToString());
    }

    private void btnChecking_Click(object sender, EventArgs e)
    {
        bankfactory i = new bankfactory();
        Checking ch = (Checking)i.getbankType("Checking");
        MessageBox.Show(ch.CalculateInterest().ToString());


    }

BANK FACTORY FORM

Aucun commentaire:

Enregistrer un commentaire