Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public class Person {
  2. private int weight;
  3. private int age;
  4. private String name;
  5. private String pesel;
  6.  
  7. public Person() {};
  8.  
  9. public Person(String name) {
  10. this.name = name;
  11. }
  12.  
  13. public Person(int weight, int age, String name, String pesel) {
  14. this.weight = weight;
  15. this.age = age;
  16. this.name = name;
  17. this.pesel = pesel;
  18. }
  19.  
  20. public int getAge() {
  21. return age;
  22. }
  23.  
  24. public String getPesel() {
  25. return pesel;
  26. }
  27.  
  28. public int getWeight() {
  29. return weight;
  30. }
  31.  
  32. public String getName() {
  33. return name;
  34. }
  35.  
  36. public void setAge(int age) {
  37. this.age = age;
  38. }
  39.  
  40. public void setPesel(String pesel) {
  41. this.pesel = pesel;
  42. }
  43.  
  44. public void setWeight(int weight) {
  45. this.weight = weight;
  46. }
  47.  
  48. public void setName(String name) {
  49. this.name = name;
  50. }
  51.  
  52.  
  53. //w pozniejszym etapie nauki zamienic + na StringBuilder i wygooglowac: "Why use stringbuilder instead of + in java?"
  54. @Override
  55. public String toString() {
  56. return "Imie: " + name + ", wiek: " + age + ", waga: " + weight + ", PESEL: " + pesel;
  57. }
  58.  
  59. @Override
  60. public boolean equals(Object obj) {
  61. if (obj == null)
  62. return false;
  63. else if (obj instanceof Person) {
  64. Person other = (Person) obj;
  65. return pesel.equals(other.pesel);
  66. } else
  67. return false;
  68. }
  69.  
  70. @Override
  71. public int hashCode() {
  72. return pesel.hashCode();
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement