Mavzu: Ob'ektga yo'naltirilgan dasturlash. Reja: I. Kirish. II. Asosiyqism



Download 44,87 Kb.
bet4/6
Sana16.12.2022
Hajmi44,87 Kb.
#888320
1   2   3   4   5   6
Bog'liq
Mavzu Ob\'ektga yo\'naltirilgan dasturlash. Reja I. Kirish. II.

2.Sinf yaratish 2-qism.
Qoidaga ko'ra, bank hisobvaraqlari o'z-o'zidan mavjud emas, balki hisobvaraqlar konteyneri vazifasini bajaradigan va ularni boshqarish funktsiyalarini bajaradigan bank ichida mavjud. Shunday qilib, keling , BankLibrary loyihasiga yangi bank sinfini qo'shamiz :
// hisob turi
public enum AccountType
{
Ordinary,
Deposit
}
public class Bank where T : Account
{
T[] accounts;
public string Name { get; private set; }
public Bank(string name)
{
this.Name = name;
}
// hisob yaratish usuli
public void Open(AccountType accountType, decimal sum,
AccountStateHandler addSumHandler, AccountStateHandler withdrawSumHandler,
AccountStateHandler calculationHandler, AccountStateHandler closeAccountHandler,
AccountStateHandler openAccountHandler)
{
T newAccount = null;
switch (accountType)
{
case AccountType.Ordinary:
newAccount = new DemandAccount(sum, 1) as T;
break;
case AccountType.Deposit:
newAccount = new DepositAccount(sum, 40) as T;
break;
}
if (newAccount == null)
throw new Exception("hisobni yaratishda xatolik");
// hisoblar qatoriga yangi sxema qo’shing
if (accounts == null)
accounts = new T[] { newAccount };
else
{
T[] tempAccounts = new T[accounts.Length + 1];
for (int i = 0; i < accounts.Length; i++)
tempAccounts[i] = accounts[i];
tempAccounts[tempAccounts.Length - 1] = newAccount;
accounts = tempAccounts;
}
// hisob voqealari ishlov beruvchilarini sozlang
newAccount.Added += addSumHandler;
newAccount.Withdrawed += withdrawSumHandler;
newAccount.Closed += closeAccountHandler;
newAccount.Opened += openAccountHandler;
newAccount.Calculated += calculationHandler;
newAccount.Open();
}
//o’rtacha hisobni yaratish
public void Put(decimal sum, int id)
{
T account = FindAccount(id);
if (account == null)
throw new Exception("hisob topilmadi");
account.Put(sum);
}
// pul mablag’ini olib qo’yish
public void Withdraw(decimal sum, int id)
{
T account = FindAccount(id);
if (account == null)
throw new Exception("Счет не найден");
account.Withdraw(sum);
}
// hisobni yopish
public void Close(int id)
{
int index;
T account = FindAccount(id, out index);
if (account == null)
throw new Exception("hisob topilmadi");
account.Close();
if (accounts.Length <= 1)
accounts = null;
else
{
// undanyopiq hisobni olib tashlash
T[] tempAccounts = new T[accounts.Length - 1];
for (int i = 0, j=0; i < accounts.Length; i++)
{
if (i != index)
tempAccounts[j++] = accounts[i];
}
accounts = tempAccounts;
}
}
// hisoblar bo’yicha foizlarni hisoblash
public void CalculatePercentage()
{
if (accounts == null) // massiv yaratilmagan bo’lsa usuldan chiqing
return;
for (int i = 0; i < accounts.Length; i++)
{
accounts[i].IncrementDays();
accounts[i].Calculate();
}

Download 44,87 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish