Advertisement
jwrbg

Untitled

Jun 9th, 2019
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. package CarSalesman;
  2.  
  3. public class Engine {
  4.     private String model;
  5.     private int power;
  6.     private int displacement;
  7.     private String efficiency;
  8.  
  9.     public Engine(String model, int power) {
  10.         this.model = model;
  11.         this.power = power;
  12.         this.displacement = 0;
  13.         this.efficiency = "n/a";
  14.     }
  15.  
  16.     public Engine(String model, int power, int displacement) {
  17.         this(model, power);
  18.         this.displacement = displacement;
  19.     }
  20.  
  21.     public Engine(String model, int power, String efficiency) {
  22.         this(model, power);
  23.         this.efficiency = efficiency;
  24.     }
  25.  
  26.     public Engine(String model, int power, int displacement, String efficiency) {
  27.         this(model, power, efficiency);
  28.      this.displacement=displacement;
  29.  
  30.     }
  31.  
  32.     public String setDisplacement() {
  33.         String a = "";
  34.         if (displacement == 0) {
  35.             a = "n/a";
  36.  
  37.         }
  38.         return a;
  39.     }
  40.  
  41.     public String getModel() {
  42.         return this.model;
  43.     }
  44.     public int getPower(){
  45.         return this.power;
  46.     }
  47.     public String getEfficiency(){
  48.         return this.efficiency;
  49.     }
  50.     public String printed(){
  51.         if(this.displacement==0){
  52.             return String.format("n/a");
  53.         }
  54.         return String.format("%d",this.displacement);}
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement