Advertisement
SIRAKOV4444

Untitled

Jun 14th, 2020
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public class Car {
  2. private String brand;
  3. private String model;
  4. private int horsePower;
  5.  
  6.  
  7. // конструктор
  8.  
  9. public Car(String brand) {
  10. this(brand, "unknown", -1);
  11.  
  12. }
  13.  
  14. public Car(String brand, String model) {
  15. this(brand, model, -1);
  16. }
  17.  
  18. public Car(String brand, String model, int horsePower) {
  19. this.brand = brand;
  20. this.model = model;
  21. this.horsePower = horsePower;
  22.  
  23. }
  24.  
  25. // гетъри и сетъри
  26. public String getBrand() {
  27. return brand;
  28. }
  29.  
  30. public void setBrand(String brand) {
  31. this.brand = brand;
  32. }
  33.  
  34. public String getModel() {
  35. return model;
  36. }
  37.  
  38. public void setModel(String model) {
  39. this.model = model;
  40. }
  41.  
  42. public int getHorsePower() {
  43. return horsePower;
  44. }
  45.  
  46. public void setHorsePower(int horsePower) {
  47. this.horsePower = horsePower;
  48. }
  49.  
  50. // къстъм метод
  51. public String getInfo() {
  52. return String.format("The car is: %s %s - %d HP.", this.brand, this.model, this.horsePower);
  53. }
  54.  
  55.  
  56.  
  57. @Override
  58. public String toString() {
  59. return getBrand() + " " + getModel() + " " + getHorsePower();
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement