DasT1k

ЛР6.3 САПР

Mar 19th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. using System;
  2.  
  3. namespace FileDetails
  4. {
  5.     enum AccountType
  6.     {
  7.         Checking,
  8.         Deposit
  9.     }
  10.     class BankAccount
  11.     {
  12.         private long accNo;
  13.         private decimal accBal;
  14.         private AccountType accType;
  15.         public void Populate(decimal balance)
  16.         {
  17.             accNo = NextNumber();
  18.             accBal = balance;
  19.             accType = AccountType.Checking;
  20.         }
  21.         public long Number()
  22.         { return accNo; }
  23.         public decimal Balance()
  24.         { return accBal; }
  25.         public string Type()
  26.         { return accType.ToString(); }
  27.         private static long nextAccNo = 123;
  28.         private static long NextNumber()
  29.         { return nextAccNo++; }
  30.         public decimal Deposit(decimal amount)
  31.         {
  32.             accBal += amount;
  33.             return accBal;
  34.         }      
  35.         public bool Withdraw(decimal amount)
  36.         {
  37.             bool sufficientFunds = accBal >= amount;
  38.             if (sufficientFunds)
  39.             { accBal -= amount; }
  40.             return sufficientFunds;
  41.         }
  42.     }
  43.     class CreateAccount
  44.     {
  45.         static void Main()
  46.         {
  47.             BankAccount berts = NewBankAccount();
  48.             Write(berts);
  49.             TestDeposit(berts);
  50.             Write(berts);
  51.             TestWithdraw(berts);
  52.             Write(berts);
  53.             BankAccount freds = NewBankAccount();
  54.             Write(freds);
  55.             TestDeposit(freds);
  56.             Write(freds);
  57.             TestWithdraw(freds);
  58.             Write(freds);
  59.         }
  60.         static BankAccount NewBankAccount()
  61.         {
  62.             BankAccount created = new BankAccount();            
  63.             /* Console.Write("Enter the account number   : ");
  64.             long number = long.Parse(Console.ReadLine()); */
  65.             // long number = BankAccount.NextNumber();
  66.             Console.Write("Enter the account balance! : ");
  67.             decimal balance = decimal.Parse(Console.ReadLine());            
  68.             /* created.accNo = number;
  69.             created.accBal = balance;
  70.             created.accType = AccountType.Checking; */
  71.             created.Populate(balance);
  72.             return created;
  73.         }        
  74.         static void Write(BankAccount toWrite)
  75.         {
  76.             Console.WriteLine("Account number is {0}", toWrite.Number());
  77.             Console.WriteLine("Account balance is {0}", toWrite.Balance());
  78.             Console.WriteLine("Account type is {0}", toWrite.Type());
  79.         }
  80.         public static void TestDeposit(BankAccount acc)
  81.         {
  82.             Console.Write("Enter amount to deposit: ");
  83.             decimal amount = decimal.Parse(Console.ReadLine());
  84.             acc.Deposit(amount);
  85.         }
  86.         public static void TestWithdraw(BankAccount acc)
  87.         {
  88.             Console.Write("Enter amount to withdraw: ");
  89.             decimal amount = decimal.Parse(Console.ReadLine());
  90.             if (!acc.Withdraw(amount))
  91.             { Console.WriteLine("Insufficient funds."); }
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment