LoraOrliGeo

CarSalesman_Car

Jun 13th, 2019
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. public class Car {
  2.     private String model;
  3.     private Engine engine;
  4.     private int weight;
  5.     private String color;
  6.  
  7.     public Car(String model, Engine engine) {
  8.         this.model = model;
  9.         this.engine = engine;
  10.         this.color = "n/a";
  11.     }
  12.  
  13.     public Car(String model, Engine engine, int weight, String color) {
  14.         this(model, engine);
  15.         this.weight = weight;
  16.         this.color = color;
  17.     }
  18.  
  19.     public Car(String model, Engine engine, int weight) {
  20.         this(model, engine);
  21.         this.weight = weight;
  22.         this.color = "n/a";
  23.     }
  24.  
  25.     public Car(String model, Engine engine, String color) {
  26.         this(model, engine);
  27.         this.color = color;
  28.     }
  29.  
  30.     public String getModel(){
  31.         return this.model;
  32.     }
  33.  
  34.     public Engine getEngine(){
  35.         return this.engine;
  36.     }
  37.  
  38.     @Override
  39.     public String toString() {
  40.         String weight = this.weight + "";
  41.         if (this.weight == 0){
  42.             weight = "n/a";
  43.         }
  44.  
  45.         String output = String.format("Weight: %s\n" +
  46.                 "Color: %s", weight, this.color);
  47.         return output;
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment