Advertisement
polpoteu

JAVA Ludziki Class

Dec 20th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. package e9ludziki;
  2.  
  3. public class E9Ludziki {
  4.  
  5. public static void main(String[] args) {
  6. Facet gostek1 = new Facet();
  7. System.out.println(gostek1.getImie());
  8. gostek1.setImie("Henrjiu");
  9. System.out.println(gostek1.getImie());
  10. System.out.println(gostek1);
  11. Facet gostek2 = new Facet("Tonik",35,176);
  12. System.out.println(gostek2);
  13. System.out.println(gostek2.getImie()+ " waży "+ gostek2.waga()+"kg.");
  14. Baba kobita1 = new Baba("Zuzia",20,164);
  15. System.out.println(kobita1.toString());
  16. System.out.println(kobita1.getImie() + " waży "+kobita1.waga());
  17. }
  18.  
  19. }
  20. class Baba extends Facet {
  21. public Baba (String imie, int wiek, int wzrost) {
  22. this.imie = imie; this.wiek = wiek; this.wzrost = wzrost;}
  23. public double waga(){
  24. return this.getWzrost() - 140+0.2*this.getWiek();
  25. }
  26. }
  27. class Facet {
  28. public double waga(){
  29. return wzrost - 110+0.2*wiek;
  30. }
  31. public String toString(){
  32. return "Nazywam się " +imie+ ", mam " + wiek + " lat oraz " + wzrost + "cm wzrostu :)";
  33. }
  34. public Facet (String imie, int wiek, int wzrost) {
  35. this.imie = imie; this.wiek = wiek; this.wzrost = wzrost;
  36. }
  37. public Facet() {
  38. imie = "Szczepan";
  39. wiek = 20;
  40. wzrost = 182;
  41. }
  42. protected String imie;
  43. protected int wiek;
  44. protected int wzrost;
  45.  
  46. /**
  47. * @return the imie
  48. */
  49. public String getImie() {
  50. return imie;
  51. }
  52.  
  53. /**
  54. * @param imie the imie to set
  55. */
  56. public void setImie(String imie) {
  57. this.imie = imie;
  58. }
  59.  
  60. /**
  61. * @return the wiek
  62. */
  63. public int getWiek() {
  64. return wiek;
  65. }
  66.  
  67. /**
  68. * @param wiek the wiek to set
  69. */
  70. public void setWiek(int wiek) {
  71. this.wiek = wiek;
  72. }
  73.  
  74. /**
  75. * @return the wzrost
  76. */
  77. public int getWzrost() {
  78. return wzrost;
  79. }
  80.  
  81. /**
  82. * @param wzrost the wzrost to set
  83. */
  84. public void setWzrost(int wzrost) {
  85. this.wzrost = wzrost;
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement