Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- namespace BankAccounts
- {
- abstract class BaseAccount
- {
- protected string fullName;
- protected int number, interstRate, foundDate, term, timeLeft;
- protected double balance;
- public double Balance
- {
- get { return balance; }
- set { balance = value; }
- }
- public int Number
- {
- get { return number; }
- }
- protected BaseAccount(string fullName, int number, int balance, int interstRate, int foundDate, int term)
- {
- this.fullName = fullName;
- this.number = number;
- this.balance = balance;
- this.interstRate = interstRate;
- this.foundDate = foundDate;
- this.term = term;
- }
- public virtual string ShowFullInfo()
- {
- return String.Format("ФИО: {0}, Номер: {1}, Процентная ставка: {2}, Дата открытия: {3}, Время обслуживания: {4}, Времени осталось: {5} ", fullName, number, interstRate, foundDate, term, timeLeft);
- }
- public void DecreaseLeftTime()
- {
- term--;
- }
- public virtual void BalanceCheckin()
- {
- if (timeLeft == 0)
- {
- balance += balance * (0.01 * interstRate);
- Console.WriteLine("Начислено {0}: ", balance * (0.01 * interstRate));
- }
- }
- public virtual void Withdraw(double quantity)
- {
- if (balance >= quantity)
- {
- balance -= quantity;
- Console.WriteLine("Выдано: {0}", quantity);
- }
- }
- public virtual void Deposit(double quantity)
- {
- balance += quantity;
- Console.WriteLine("Счет пополнен на: {0}", quantity);
- }
- public virtual void ShowBalance()
- {
- Console.WriteLine("Текущий баланс: {0}", balance);
- }
- }
- class SavingAccount : BaseAccount
- {
- public SavingAccount(string fullName, int number, int balance, int interstRate, int foundDate, int term) : base(fullName, number, balance, interstRate, foundDate, term)
- {
- }
- }
- class TimedMaturityAccount : BaseAccount
- {
- public TimedMaturityAccount(string fullName, int number, int balance, int interstRate, int foundDate, int term) : base(fullName, number, balance, interstRate, foundDate, term)
- {
- }
- public override void Withdraw(double quantity)
- {
- if (balance >= quantity)
- {
- balance -= quantity;
- Console.WriteLine("Выдано: {0}", quantity * ((timeLeft > 0) ? 1 - 0.01 * interstRate : 1));
- }
- }
- }
- class ChekingAccount : BaseAccount
- {
- int operationsQuantity, fine;
- public ChekingAccount(string fullName, int number, int balance, int interstRate, int foundDate, int term, int operationsQuantity, int fine) : base(fullName, number, balance, interstRate, foundDate, term)
- {
- this.operationsQuantity = operationsQuantity;
- this.fine = fine;
- }
- public override void BalanceCheckin()
- {
- Console.WriteLine("Проценты не начисляются");
- }
- private void FineCheck()
- {
- if (operationsQuantity <= 0)
- {
- balance -= fine;
- }
- operationsQuantity--;
- }
- public override void Deposit(double quantity)
- {
- base.Deposit(quantity);
- FineCheck();
- }
- public override void Withdraw(double quantity)
- {
- base.Withdraw(quantity);
- FineCheck();
- }
- public override void ShowBalance()
- {
- base.ShowBalance();
- FineCheck();
- }
- public override string ShowFullInfo()
- {
- return base.ShowFullInfo() + String.Format("Количество доступных операций: {0}, Штраф: {1}", operationsQuantity, fine);
- }
- }
- class Program
- {
- static void Main()
- {
- List <BaseAccount> Accounts = new List <BaseAccount>();
- StreamReader readFile;
- StreamWriter outputFile;
- try
- {
- readFile = new StreamReader("input.txt");
- outputFile = new StreamWriter("output.txt");
- } catch (Exception e)
- {
- Console.WriteLine(e.Message);
- return;
- }
- {
- string temp;
- string[] tempArray = new string[9];
- while ((temp = readFile.ReadLine()) != null)
- {
- tempArray = temp.Split(' ');
- if (tempArray[0] == "SavingAccount")
- {
- Accounts.Add(new SavingAccount(tempArray[1], int.Parse(tempArray[2]), int.Parse(tempArray[3]), int.Parse(tempArray[4]), int.Parse(tempArray[5]), int.Parse(tempArray[6])));
- }
- if (tempArray[0] == "TimedMaturityAccount")
- {
- Accounts.Add(new TimedMaturityAccount(tempArray[1], int.Parse(tempArray[2]), int.Parse(tempArray[3]), int.Parse(tempArray[4]), int.Parse(tempArray[5]), int.Parse(tempArray[6])));
- }
- if (tempArray[0] == "CheckingAccount")
- {
- Accounts.Add(new ChekingAccount(tempArray[1], int.Parse(tempArray[2]), int.Parse(tempArray[3]), int.Parse(tempArray[4]), int.Parse(tempArray[5]), int.Parse(tempArray[6]), int.Parse(tempArray[7]), int.Parse(tempArray[8])));
- }
- }
- }
- foreach(BaseAccount value in Accounts)
- {
- Console.WriteLine("{0} \n", value.ShowFullInfo());
- }
- foreach(BaseAccount value in Accounts)
- {
- Console.WriteLine(value.GetType().ToString());
- if(value.GetType().ToString() == "TimedMaturityAccount")
- {
- outputFile.WriteLine(value.ShowFullInfo());
- }
- }
- {
- int from, to, sum;
- BaseAccount tmp = null;
- from = int.Parse(Console.ReadLine());
- to = int.Parse(Console.ReadLine());
- sum = int.Parse(Console.ReadLine());
- foreach (BaseAccount value in Accounts)
- {
- if (value.Balance >= sum && value.Number == from)
- {
- tmp = value;
- }
- }
- foreach (BaseAccount value in Accounts)
- {
- if (value.Number == to && tmp != null)
- {
- tmp.Balance -= sum;
- value.Balance += sum;
- }
- }
- }
- {
- int fineQuantity = 0;
- foreach (BaseAccount value in Accounts)
- {
- value.BalanceCheckin();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement