SHARE
TWEET

Car

a guest Oct 15th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Car {
  2.     private String model;
  3.     private Engine engine;
  4.     private String weight = "n/a";
  5.     private String color = "n/a";
  6.  
  7.     public Car(String model, Engine engine) {
  8.         this.model = model;
  9.         this.engine = engine;
  10.     }
  11.  
  12.     public Car(String model, Engine engine, int weight) {
  13.         this.model = model;
  14.         this.engine = engine;
  15.         this.weight = String.valueOf(weight);
  16.     }
  17.  
  18.     public Car(String model, Engine engine, String color) {
  19.         this.model = model;
  20.         this.engine = engine;
  21.         this.color = color;
  22.     }
  23.  
  24.     public Car(String model, Engine engine, int weight, String color) {
  25.         this.model = model;
  26.         this.engine = engine;
  27.         this.weight = String.valueOf(weight);
  28.         this.color = color;
  29.     }
  30.  
  31.     @Override
  32.     public String toString() {
  33.         StringBuilder sb = new StringBuilder();
  34.  
  35.         sb.append(this.model).append(":").append(System.lineSeparator());
  36.         sb.append(this.engine.toString()).append(System.lineSeparator());
  37.         sb.append("Weight: ").append(this.weight).append(System.lineSeparator());
  38.         sb.append("Color: ").append(this.color);
  39.  
  40.         return sb.toString();
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top