Advertisement
Guest User

bemmater

a guest
May 26th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.38 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. using System.Threading;
  7.  
  8. namespace ZADATAK_BANKA
  9. {
  10.     class Program
  11.     {
  12.  
  13.         static int k = 0;
  14.         static int brojUplatnica = 0;
  15.         static AutoResetEvent a = new AutoResetEvent(true);
  16.         static SemaphoreSlim semafor = new SemaphoreSlim(15);
  17.  
  18.         static int red1 = 0;
  19.         static int red2 = 0;
  20.         static int red3 = 0;
  21.  
  22.         static void radnoVreme()
  23.         {
  24.             Thread.Sleep(17000);
  25.             k++;
  26.             Console.WriteLine("........POSTA SE ZATVARA........\n");
  27.         }
  28.  
  29.  
  30.         static void Salter3()
  31.         {
  32.             Console.WriteLine("Klijent popunjava uplatnicu/ce na salteru 3.");
  33.             red3++;
  34.             Thread.Sleep(brojUplatnica * 40);
  35.             Console.WriteLine("KLIJENT IZLAZI SA SALTERA.");
  36.             red3--;
  37.             Console.WriteLine("Klijent prolazi pored obezbedjenja i izlazi iz banke.");
  38.             semafor.Release();
  39.         }
  40.  
  41.         static void Salter1()
  42.         {
  43.             Console.WriteLine("Klijent popunjava uplatnicu/ce na salteru 1.");
  44.             red1++;
  45.             Thread.Sleep(brojUplatnica * 40);
  46.             Console.WriteLine("KLIJENT IZLAZI SA SALTERA.");
  47.             red1--;
  48.             Console.WriteLine("Klijent prolazi pored obezbedjenja i izlazi iz banke.");
  49.             semafor.Release();
  50.         }
  51.  
  52.         static void Salter2()
  53.         {
  54.             Console.WriteLine("Klijent popunjava uplatnicu/ce na salteru 2.");
  55.             red2++;
  56.             Thread.Sleep(brojUplatnica * 40);
  57.             Console.WriteLine("KLIJENT IZLAZI SA SALTERA.");
  58.             red2--;
  59.             Console.WriteLine("Klijent prolazi pored obezbedjenja i izlazi iz banke.");
  60.             semafor.Release();
  61.         }
  62.  
  63.         static int najmanji()
  64.         {
  65.             if(red1 > red2)
  66.             {
  67.                 return 2;
  68.             }
  69.             if(red1 < red2)
  70.             {
  71.                 return 1;
  72.             }
  73.             else
  74.             {
  75.                 return 50;
  76.             }
  77.  
  78.         }
  79.  
  80.         static void Banka()
  81.         {
  82.        
  83.             a.WaitOne();
  84.             Console.WriteLine("Klijent je usao u banku.");
  85.             Console.WriteLine("Obezbedjenje provera klijenta.");
  86.             a.Reset();
  87.             semafor.Wait();
  88.             Console.WriteLine("Klijent popunjava uplatnice.");
  89.             Random r = new Random();
  90.             brojUplatnica = r.Next(1, 5);
  91.             Console.WriteLine("Klijent ime {0} uplatnica.", brojUplatnica);
  92.             int najmanjiRed = najmanji();
  93.  
  94.             if(brojUplatnica > 3)
  95.             {
  96.                 Salter3();
  97.             }
  98.             else if (brojUplatnica < 3 && najmanjiRed==1)
  99.             {
  100.                 Salter1();
  101.             }
  102.             else if(najmanjiRed==2)
  103.             {
  104.                 Salter2();
  105.             }
  106.         }
  107.  
  108.         static void Main(string[] args)
  109.         {
  110.             Thread nit = new Thread(radnoVreme);
  111.             nit.Start();
  112.             while(k == 0)
  113.             {
  114.                 Thread t = new Thread(Banka);
  115.                 t.Start();
  116.                 Thread.Sleep(70);
  117.             }
  118.             Console.WriteLine("Broj izvrsenih uplata je: {0}", brojUplatnica);
  119.             Console.ReadLine();
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement