STEP 1: Understand the UML Diagram Engine: -cylinders: int -horsepower:int +Engi
ID: 3641904 • Letter: S
Question
STEP 1: Understand the UML DiagramEngine: -cylinders: int -horsepower:int +Engine() +Engine(in cylinders: int , in horsePower :int) +toString(): string (1 to 1 to Racer) Racer: -name: string -speed: int -eng: Engine +Racer() +Racer(in name: string, in speed:int, in engine: Engine) +isDead():bool +toString():string HotRod (point to Racer): -blower:bool +HotRod() +HotRod(in name: string, in speed: int, in engine: Engine, in blower: bool) +isDead():bool +toString():string StreetTuner (point to Racer): -nitrous: bool +StreetTuner() +StreetTuner(in name: string, in speed:int, in engine: Engine, in nitrous:bool) +isDead():bool +toString(): string
Explanation / Answer
public class Engine {
private int cylinders;
private int horsePower;
public Engine() {
}
public Engine(int cylinders, int horsePower) {
this.cylinders = cylinders;
this.horsePower = horsePower;
}
public String toString() {
return " **Engine Information**"
+ " Cylinders : " + this.getCylinders()
+ " Horse Power : " + this.getHorsePower();
}
public int getCylinders() {
return cylinders;
}
public void setCylinders(int cylinders) {
this.cylinders = cylinders;
}
public int getHorsePower() {
return horsePower;
}
public void setHorsePower(int horsePower) {
this.horsePower = horsePower;
}
}
public class Engine {
private int cylinders;
private int horsePower;
public Engine() {
}
public Engine(int cylinders, int horsePower) {
this.cylinders = cylinders;
this.horsePower = horsePower;
}
public String toString() {
return " **Engine Information**"
+ " Cylinders : " + this.getCylinders()
+ " Horse Power : " + this.getHorsePower();
}
public int getCylinders() {
return cylinders;
}
public void setCylinders(int cylinders) {
this.cylinders = cylinders;
}
public int getHorsePower() {
return horsePower;
}
public void setHorsePower(int horsePower) {
this.horsePower = horsePower;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.