Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 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 ConsoleApplication1
  8. {
  9. public class Osoba
  10. {
  11. public string Imie;
  12. public string Nazwisko;
  13. public int Wiek
  14. {
  15. get // pobiera wartość zmiennej
  16. {
  17. return _wiek;
  18. }
  19. set // ustawia wartość zmiennej
  20. {
  21. if (value <= 10)
  22. {
  23. Console.WriteLine("Masz 10 lat!");
  24. }
  25. _wiek = value;
  26. }
  27. }
  28.  
  29. public int Wzrost;
  30. public int Waga;
  31.  
  32. private string _imie;
  33. private string _nazwisko;
  34. private int _wiek;
  35. private int _wzrost;
  36. private int _waga;
  37.  
  38. private float _bmi;
  39. private Osoba() // prywatny konstruktor
  40. {
  41. Imie = "";
  42. Nazwisko = "";
  43. this._wiek = 0;
  44. Wzrost = 0;
  45. Waga = 0;
  46. }
  47.  
  48. public Osoba(string _imie, string _nazwisko, int _wiek, int _wzrost, int _waga) : this()
  49. {
  50. this._imie = _imie;
  51. this._nazwisko = _nazwisko;
  52. Wiek = _wiek;
  53. this._wzrost = _wzrost;
  54. this._waga = _waga;
  55. }
  56. public void WyswietlDane()
  57. {
  58. Console.WriteLine($"Imie:{_imie} Nazwisko:{_nazwisko} Wiek:{_wiek} Wzrost:{_wzrost}");
  59. }
  60. public float ObliczanieBMI()
  61. {
  62. _bmi = ((float)Waga / ((float)(Wzrost * Wzrost)))*10000.0f;
  63. return _bmi;
  64. }
  65. }
  66. }
  67.  
  68.  
  69. using System;
  70. using System.Collections.Generic;
  71. using System.Linq;
  72. using System.Text;
  73. using System.Threading.Tasks;
  74.  
  75. namespace ConsoleApplication1
  76. {
  77. class Program
  78. {
  79. static void Main(string[] args)
  80. {
  81. try
  82. {
  83. Osoba _osoba = new Osoba("Jan", "Nowak", 8, 140, 60);
  84. _osoba.WyswietlDane();
  85. }
  86. catch (Exception e)
  87. {
  88. Console.WriteLine($"Wyjatek ! {e.Message}");
  89. }
  90. Console.ReadKey();
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement