class Engine {
constructor() {
this.spin = 0;
}
start(spin) {
this.spin = Math.min(spin, 3000);
}
}
class StarterMotor {
constructor() {
this.spin = 0;
}
start(charge) {
if (charge > 50) {
this.spin = 2500;
}
}
}
class Battery {
constructor() {
this.charge = 0;
}
}
class Car {
constructor() {
this.battery = new Battery();
this.starter = new StarterMotor();
this.engine = new Engine();
}
turnKey() {
this.starter.start(this.battery.charge);
this.engine.start(this.starter.spin);
if (this.engine.spin > 0) {
console.log("Engine started");
} else {
console.log("Engine not started");
}
}
jump() {
this.battery.charge = 100;
console.log("Jumped");
}
}
module.exports = Car;