idzik

Junior-Java-Developer-Czlowiek

Nov 23rd, 2016
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.  
  2. public class Czlowiek implements Comparable<Czlowiek>{
  3. private String name;
  4. private String surname;
  5. private int age;
  6. private int height;
  7. private int weight;
  8.  
  9.  
  10.  
  11. public String getName() {
  12.     return name;
  13. }
  14.  
  15.  
  16.  
  17. public void setName(String name) {
  18.     this.name = name;
  19. }
  20.  
  21.  
  22.  
  23. public String getSurname() {
  24.     return surname;
  25. }
  26.  
  27.  
  28.  
  29. public void setSurname(String surname) {
  30.     this.surname = surname;
  31. }
  32.  
  33.  
  34.  
  35. public int getAge() {
  36.     return age;
  37. }
  38.  
  39.  
  40.  
  41. public void setAge(int age) {
  42.     if(age>0)
  43.     this.age = age;
  44.     else
  45.         this.age=0;
  46. }
  47.  
  48.  
  49.  
  50. public int getHeight() {
  51.     return height;
  52. }
  53.  
  54.  
  55.  
  56. public void setHeight(int height) {
  57.     if(height>0)
  58.     this.height = height;
  59.     else this.height=0;
  60. }
  61.  
  62.  
  63.  
  64. public int getWeight() {
  65.     return weight;
  66. }
  67.  
  68.  
  69.  
  70. public void setWeight(int weight) {
  71.     if(weight>0)
  72.     this.weight = weight;
  73.     else this.weight=0;
  74. }
  75.  
  76.  
  77.  
  78. public Czlowiek(String name, String surname, int age, int height, int weight) {
  79.     super();
  80.     setName(name);
  81.     setSurname(surname);
  82.     setAge(age);
  83.     setHeight(height);
  84.     setWeight(weight);
  85. }
  86.  
  87.  
  88.  
  89. @Override
  90. public String toString() {
  91.     return "Czlowiek [name=" + name + ", surname=" + surname + ", age=" + age + ", height=" + height + ", weight="
  92.             + weight + "]";
  93. }
  94.  
  95.  
  96.  
  97. public static void biegnij(){
  98.     System.out.println("Biegnę");
  99. }
  100.  
  101.  
  102.  
  103. @Override
  104. public int compareTo(Czlowiek czl) {
  105.     if (this.age<czl.age) return -1;
  106.     else if (this.age>czl.age) return 1;
  107.     return 0;
  108. }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment