Advertisement
vkarakolev

car

Jun 21st, 2021
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. public class Car {
  2.     private String brand;
  3.     private String model;
  4.     private int horsePower;
  5.  
  6.     public Car (String brand){
  7.         this(brand, "unknown", -1);
  8.     }
  9.  
  10.     public Car (String brand, String model, int horsePower){
  11.         this.setBrand(brand);
  12.         this.setModel(model);
  13.         this.setHorsePower(horsePower);
  14.     }
  15.  
  16.     @Override
  17.     public String toString() {
  18.         return String.format("The car is: %s %s - %d HP.",
  19.                 this.getBrand(), this.getModel(), this.getHorsePower());
  20.     }
  21.  
  22.     public String getBrand() {
  23.         return brand;
  24.     }
  25.  
  26.     public void setBrand(String brand) {
  27.         this.brand = brand;
  28.     }
  29.  
  30.     public String getModel() {
  31.         return model;
  32.     }
  33.  
  34.     public void setModel(String model) {
  35.         this.model = model;
  36.     }
  37.  
  38.     public int getHorsePower() {
  39.         return horsePower;
  40.     }
  41.  
  42.     public void setHorsePower(int horsePower) {
  43.         this.horsePower = horsePower;
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement