Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.56 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4.  
  5. namespace BankAccounts
  6. {
  7.     abstract class BaseAccount
  8.     {
  9.         protected string fullName;
  10.         protected int number, interstRate, foundDate, term, timeLeft;
  11.         protected double balance;
  12.  
  13.         public double Balance
  14.         {
  15.             get { return balance; }
  16.             set { balance = value; }
  17.         }
  18.  
  19.         public int Number
  20.         {
  21.             get { return number; }
  22.         }
  23.  
  24.         protected BaseAccount(string fullName, int number, int balance, int interstRate, int foundDate, int term)
  25.         {
  26.             this.fullName = fullName;
  27.             this.number = number;
  28.             this.balance = balance;
  29.             this.interstRate = interstRate;
  30.             this.foundDate = foundDate;
  31.             this.term = term;
  32.         }
  33.  
  34.         public virtual string ShowFullInfo()
  35.         {
  36.             return String.Format("ФИО: {0}, Номер: {1}, Процентная ставка: {2}, Дата открытия: {3}, Время обслуживания: {4}, Времени осталось: {5} ", fullName, number, interstRate, foundDate, term, timeLeft);
  37.         }
  38.  
  39.         public void DecreaseLeftTime()
  40.         {
  41.             term--;
  42.         }
  43.  
  44.         public virtual void BalanceCheckin()
  45.         {
  46.             if (timeLeft == 0)
  47.             {
  48.                 balance += balance * (0.01 * interstRate);
  49.                 Console.WriteLine("Начислено {0}: ", balance * (0.01 * interstRate));
  50.             }
  51.         }
  52.  
  53.         public virtual void Withdraw(double quantity)
  54.         {
  55.             if (balance >= quantity)
  56.             {
  57.                 balance -= quantity;
  58.                 Console.WriteLine("Выдано: {0}", quantity);
  59.             }
  60.         }
  61.  
  62.         public virtual void Deposit(double quantity)
  63.         {
  64.             balance += quantity;
  65.             Console.WriteLine("Счет пополнен на: {0}", quantity);
  66.         }
  67.  
  68.         public virtual void ShowBalance()
  69.         {
  70.             Console.WriteLine("Текущий баланс: {0}", balance);
  71.         }
  72.     }
  73.  
  74.     class SavingAccount : BaseAccount
  75.     {
  76.         public SavingAccount(string fullName, int number, int balance, int interstRate, int foundDate, int term) : base(fullName, number, balance, interstRate, foundDate, term)
  77.         {
  78.  
  79.         }
  80.     }
  81.  
  82.     class TimedMaturityAccount : BaseAccount
  83.     {
  84.         public TimedMaturityAccount(string fullName, int number, int balance, int interstRate, int foundDate, int term) : base(fullName, number, balance, interstRate, foundDate, term)
  85.         {
  86.  
  87.         }
  88.  
  89.         public override void Withdraw(double quantity)
  90.         {
  91.             if (balance >= quantity)
  92.             {
  93.                 balance -= quantity;
  94.                 Console.WriteLine("Выдано: {0}", quantity * ((timeLeft > 0) ? 1 - 0.01 * interstRate : 1));
  95.             }
  96.         }
  97.     }
  98.  
  99.     class ChekingAccount : BaseAccount
  100.     {
  101.         int operationsQuantity, fine;
  102.         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)
  103.         {
  104.             this.operationsQuantity = operationsQuantity;
  105.             this.fine = fine;
  106.         }
  107.  
  108.         public override void BalanceCheckin()
  109.         {
  110.             Console.WriteLine("Проценты не начисляются");
  111.         }
  112.  
  113.         private void FineCheck()
  114.         {
  115.             if (operationsQuantity <= 0)
  116.             {
  117.                 balance -= fine;
  118.             }
  119.             operationsQuantity--;
  120.         }
  121.  
  122.         public override void Deposit(double quantity)
  123.         {
  124.             base.Deposit(quantity);
  125.             FineCheck();
  126.         }
  127.  
  128.         public override void Withdraw(double quantity)
  129.         {
  130.             base.Withdraw(quantity);
  131.             FineCheck();
  132.         }
  133.  
  134.         public override void ShowBalance()
  135.         {
  136.             base.ShowBalance();
  137.             FineCheck();
  138.         }
  139.  
  140.         public override string ShowFullInfo()
  141.         {
  142.             return base.ShowFullInfo() + String.Format("Количество доступных операций: {0}, Штраф: {1}", operationsQuantity, fine);
  143.         }
  144.     }
  145.  
  146.     class Program
  147.     {
  148.         static void Main()
  149.         {
  150.             List <BaseAccount> Accounts = new List <BaseAccount>();
  151.             StreamReader readFile;
  152.             StreamWriter outputFile;
  153.  
  154.             try
  155.             {
  156.                 readFile = new StreamReader("input.txt");
  157.                 outputFile = new StreamWriter("output.txt");
  158.             } catch (Exception e)
  159.             {
  160.                 Console.WriteLine(e.Message);
  161.                 return;
  162.             }
  163.  
  164.             {
  165.                 string temp;
  166.                 string[] tempArray = new string[9];
  167.                 while ((temp = readFile.ReadLine()) != null)
  168.                 {
  169.                     tempArray = temp.Split(' ');
  170.                     if (tempArray[0] == "SavingAccount")
  171.                     {
  172.                         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])));
  173.                     }
  174.                     if (tempArray[0] == "TimedMaturityAccount")
  175.                     {
  176.                         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])));
  177.                     }
  178.                     if (tempArray[0] == "CheckingAccount")
  179.                     {
  180.                         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])));
  181.                     }
  182.                 }
  183.             }
  184.  
  185.             foreach(BaseAccount value in Accounts)
  186.             {
  187.                 Console.WriteLine("{0} \n", value.ShowFullInfo());
  188.             }
  189.  
  190.             foreach(BaseAccount value in Accounts)
  191.             {
  192.                 Console.WriteLine(value.GetType().ToString());
  193.                 if(value.GetType().ToString() == "TimedMaturityAccount")
  194.                 {
  195.                     outputFile.WriteLine(value.ShowFullInfo());
  196.                 }
  197.             }
  198.  
  199.             {
  200.                 int from, to, sum;
  201.                 BaseAccount tmp = null;
  202.                 from = int.Parse(Console.ReadLine());
  203.                 to = int.Parse(Console.ReadLine());
  204.                 sum = int.Parse(Console.ReadLine());
  205.                
  206.  
  207.                 foreach (BaseAccount value in Accounts)
  208.                 {
  209.                     if (value.Balance >= sum && value.Number == from)
  210.                     {
  211.                         tmp = value;
  212.                     }
  213.                 }
  214.  
  215.                 foreach (BaseAccount value in Accounts)
  216.                 {
  217.                     if (value.Number == to && tmp != null)
  218.                     {
  219.                         tmp.Balance -= sum;
  220.                         value.Balance += sum;
  221.                     }
  222.                 }                
  223.             }
  224.  
  225.             {
  226.                 int fineQuantity = 0;
  227.  
  228.                 foreach (BaseAccount value in Accounts)
  229.                 {
  230.                     value.BalanceCheckin();
  231.  
  232.                 }
  233.             }
  234.            
  235.         }
  236.     }
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement