Advertisement
Guest User

person

a guest
Dec 18th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. class person
  2. {
  3. private string name;
  4. private int age;
  5. private double height;
  6. private double weight;
  7.  
  8.  
  9. public person( string newName, int newAge, double newHeight, double newWeight)
  10. {
  11. name = newName;
  12. age = newAge;
  13. height = newHeight;
  14. weight = newWeight;
  15. }
  16.  
  17. public person()
  18. {
  19. name = "no name";
  20. age = 0;
  21. height = 0.50;
  22. weight = 3.200;
  23. }
  24.  
  25.  
  26. public override string ToString()
  27. {
  28. return name + "," + age + "år" + height + "m" + weight + "kg";
  29. }
  30.  
  31. public string getName()
  32. {
  33. return name;
  34. }
  35. public void setName (string newName)
  36. {
  37. name = newName;
  38. }
  39. public int getAge()
  40. {
  41. return age;
  42. }
  43. public void setAge (int newAge)
  44. {
  45. if (newAge > 120)
  46. newAge = 0;
  47. age = newAge;
  48. }
  49. public double getHeight()
  50. {
  51. return height;
  52. }
  53. public void setHeight (double newHeight)
  54. {
  55. if (newHeight < 0 || newHeight > 2.50)
  56. {
  57. Console.WriteLine("højden skal være mellem 0 og 2.5 meter");
  58. }
  59. else height = newHeight;
  60.  
  61. }
  62. public double getWeight()
  63. {
  64. return weight;
  65. }
  66. public void setWeight (double newWeight)
  67. {
  68. }
  69. public bool isAdult()
  70. {
  71. if (age >= 18 )
  72. {
  73. return true;
  74. }
  75. else return false;
  76. }
  77. public bool isChild()
  78. {
  79. if (age < 15)
  80. {
  81. return true;
  82. }
  83. else return false;
  84.  
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement