Created
April 17, 2023 02:38
-
-
Save arisupriatna14/3359be4b2a98f8a13e93d19d0a00d0e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Engine { | |
//… | |
private double fuel; | |
private double CV; | |
public Engine(double fuel, double CV) { | |
this.fuel = fuel; | |
this.CV = CV; | |
} | |
public double getFuel() { | |
return fuel; | |
} | |
public void setFuel(double fuel) { | |
this.fuel = fuel; | |
} | |
public double getCV() { | |
return CV; | |
} | |
public void setCV(double cv) { | |
this.CV = cv; | |
} | |
} | |
class Car { | |
// ... | |
private String brand; | |
private String model; | |
private Engine engine; | |
public Car(String brand, String model, double fuel, double CV) { | |
this.brand = brand; | |
this.model = model; | |
this.engine = new Engine(fuel, CV); | |
} | |
public String getName() { | |
return brand + " " + model + " (" + engine.getCV() + "CV)"; | |
} | |
public String getModel() { | |
return model; | |
} | |
public void setModel(String model) { | |
this.model = model; | |
} | |
public String getBrand() { | |
return brand; | |
} | |
public void setBrand(String brand) { | |
this.brand = brand; | |
} | |
public double getFuel() { | |
return engine.getFuel(); | |
} | |
public void setFuel(double fuel) { | |
engine.setFuel(fuel); | |
} | |
public double getCV() { | |
return engine.getCV(); | |
} | |
public void setCV(double cv) { | |
engine.setCV(cv); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment