Adijata

RPR vježba 2, 1. a)

Oct 11th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 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.  
  8.  
  9. namespace ConsoleApplication5
  10. {
  11.  
  12.     class FudbalerU21
  13.     {
  14.         private string Ime;
  15.         private string Prezime;
  16.         private int _G_R;
  17.         private int _B_G;
  18.  
  19.         public FudbalerU21(string ime, string prezime, int gr, int bg)
  20.         {
  21.             this.Ime = ime;
  22.             this.Prezime = prezime;
  23.             this._G_R = gr;
  24.             this._B_G = bg;
  25.         }
  26.  
  27.        
  28.        
  29.         public string ime
  30.         {
  31.             set
  32.             {
  33.                 if (value == null || value == string.Empty) throw new Exception("No name provided");
  34.                 else this.Ime = value;  
  35.             }
  36.             get
  37.             {
  38.                 return this.Ime;
  39.             }
  40.         }
  41.         public int BrojGolova
  42.         { set; get; }
  43.         public int GR
  44.         { set; get; }
  45.         public string prezme
  46.         {
  47.             set
  48.             {
  49.                 if (value == null || value == string.Empty) throw new Exception("No lastname provided");
  50.                 else this.Prezime = value;
  51.             }
  52.             get
  53.             {
  54.                 return this.Prezime;
  55.             }
  56.         }
  57.         public bool DaLiJePunoljetan()
  58.         {
  59.             if (DateTime.Now.Year - GR == 21) return true; else return false;
  60.         }
  61.  
  62.        
  63.         public int godine
  64.         {
  65.             get
  66.             {
  67.                 return (DateTime.Now.Year - this._G_R);
  68.             }
  69.             set
  70.             {
  71.                 godine = DateTime.Now.Year - this._G_R;
  72.                 if (godine > 21) throw new Exception("hasjf");
  73.             }
  74.         }
  75.      
  76.  
  77.         public void Ispisi()
  78.         {
  79.             if (21 - this.godine <= 0) throw new InvalidCastException("Fudbaler je punoljetan");
  80.             Console.WriteLine(Ime + " " + Prezime + " " + _G_R + " Do punoljetnosti ostalo: {0} ", (21-this.godine));  
  81.  
  82.         }
  83.     }
  84.     class Program
  85.     {
  86.         static void Main(string[] args)
  87.         {
  88.             try
  89.             {
  90.                 FudbalerU21 NF = new FudbalerU21("Adin", "Velić", 1993, 1000);
  91.                 NF.Ispisi();
  92.                
  93.             }
  94.             catch (InvalidCastException e )
  95.             {
  96.                 Console.WriteLine(e);
  97.  
  98.             }
  99.             Console.ReadLine();
  100.  
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment