Advertisement
Adijata

rpr tut 2 nopoly nove klase

Oct 28th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Polymorphism.NoPoly
  8. {
  9.     public class Bank
  10.     {
  11.         private List<Person> Clients { get; set; }
  12.         private List<PravnoLice> Klijenti { get; set; }
  13.         private List<DrawingAccount> Accounts { get; set; }
  14.         private List<DravingAkaunt> Akaunt { get; set; }
  15.  
  16.         public Bank()
  17.         {
  18.             Clients = new List<Person>();
  19.             Accounts = new List<DrawingAccount>();
  20.         }
  21.  
  22.         public void addClient(Person p)
  23.         {
  24.             Clients.Add(p);
  25.         }
  26.  
  27.         public void dodajKlijenta(PravnoLice p)
  28.         {
  29.             Klijenti.Add(p);      
  30.  
  31.         }
  32.  
  33.         public void openAccountForPerson(Person p)
  34.         {
  35.             DrawingAccount acc = new DrawingAccount(0) {
  36.                 AccountIdentity= Accounts.Count
  37.             };
  38.             Accounts.Add(acc);
  39.             p.Accounts.Add(acc);
  40.         }
  41.         public void openAkauntForPravno( PravnoLice p)
  42.         {
  43.             DravingAkaunt acc = new DravingAkaunt(0)
  44.             {
  45.                 AkauntIdentiti = Akaunt.Count
  46.             };
  47.             Akaunt.Add(acc);
  48.             p.Akaunt.Add(acc);
  49.         }
  50.  
  51.         public Person findClient(Int32 identity)
  52.         {
  53.             return Clients.Single(person => person.Identity == identity);
  54.         }
  55.  
  56.         public void depositMoney(DrawingAccount acc, Decimal amount)
  57.         {
  58.             acc.deposit(amount);
  59.         }
  60.     }
  61. }
  62.  
  63.  
  64.  
  65.  
  66. using System;
  67. using System.Collections.Generic;
  68. using System.Linq;
  69. using System.Text;
  70. using System.Threading.Tasks;
  71.  
  72. namespace Polymorphism.NoPoly
  73. {
  74.     public class PravnoLice
  75.     {
  76.         public List<DravingAkaunt> Akaunt
  77.         {
  78.             get;
  79.             set;
  80.         }
  81.         public string Ime
  82.         {
  83.             get;
  84.             set;
  85.         }
  86.  
  87.         public string Adresa
  88.         {
  89.             get;
  90.             set;
  91.         }
  92.  
  93.         public PravnoLice()
  94.         {
  95.             Akaunt = new List<DravingAkaunt>();
  96.         }
  97.     }
  98. }
  99.  
  100.  
  101.  
  102.  
  103. using System;
  104. using System.Collections.Generic;
  105. using System.Linq;
  106. using System.Text;
  107. using System.Threading.Tasks;
  108.  
  109. namespace Polymorphism.NoPoly
  110. {
  111.     public class DravingAkaunt
  112.     {
  113.         private static Decimal limit = 1000;
  114.  
  115.         public Int32 AkauntIdentiti { get; set; }
  116.  
  117.         private Decimal _balans;
  118.  
  119.         public DravingAkaunt(Decimal startingBalance)
  120.         {
  121.             _balans = startingBalance;
  122.         }
  123.  
  124.         public Decimal Statuss
  125.         {
  126.             get
  127.             {
  128.                 return _balans;
  129.             }
  130.         }
  131.  
  132.         public void depozit(Decimal amount)
  133.         {
  134.             if (amount < 0)
  135.             {
  136.                 throw new Exception("Amount's got to be positive in order to deposit money.");
  137.             }
  138.             _balans += amount;
  139.         }
  140.  
  141.         public void withtekuci(Decimal amount)
  142.         {
  143.             if (amount < 0)
  144.             {
  145.                 throw new Exception("Amount's got to be positive in order to withdraw money.");
  146.             }
  147.             else if (amount > limit)
  148.             {
  149.                 throw new Exception("Amount's got to be smaller than security limit for single transaction.");
  150.             }
  151.             _balans -= amount;
  152.         }
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement