Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 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 Zadania
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14.  
  15. object[] osoby = new object[50];
  16.  
  17. for (int i = 0; i < 50; i++)
  18. {
  19. if (i % 2 == 0)
  20. {
  21. osoby[i] = new Osoba("Daniel", 20);
  22. }
  23. else if (i % 3 == 0)
  24. {
  25. osoby[i] = new Osoba("Karol", 19);
  26. }
  27. else
  28. osoby[i] = new Osoba("Konrad", 61);
  29. }
  30.  
  31. Console.WriteLine($"W grupie mamy {Osoba.iloscDan} Danieli, {Osoba.iloscKar} Karoli i {Osoba.iloscKon} Konradów.");
  32. Console.ReadKey();
  33. }
  34. internal class Osoba
  35. {
  36. string imie;
  37. int wiek;
  38.  
  39. public static int iloscDan;
  40. public static int iloscKon;
  41. public static int iloscKar;
  42.  
  43. public Osoba(string imie, int wiek)
  44. {
  45.  
  46. this.imie = imie;
  47. this.wiek = wiek;
  48.  
  49. if (this.imie == "Daniel")
  50. {
  51. iloscDan++;
  52. }
  53. else if (this.imie == "Konrad")
  54. {
  55. iloscKon++;
  56. }
  57. else
  58. {
  59. iloscKar++;
  60. }
  61.  
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement