Commit 96a0604c authored by Théo GORDYJAN's avatar Théo GORDYJAN

Finished the Engine package

parent fa45fb1e
This diff is collapsed.
package Engine; package Engine;
public class ElectricEngine { public class ElectricEngine extends Engine {
public ElectricEngine(String _cylindre, Double _price) {
super(_cylindre, _price);
this.type = EngineType.ELECTRIC;
}
public String toString() {
return "Electric Engine";
}
} }
...@@ -3,13 +3,13 @@ package Engine; ...@@ -3,13 +3,13 @@ package Engine;
public class Engine { public class Engine {
protected EngineType type; protected EngineType type;
private String cylindre; protected String cylindre;
private Double price; protected Double price;
public Engine (String _cylindre, Double _price) { public Engine (String _cylindre, Double _price) {
this.cylindre = _cylindre; this.cylindre = _cylindre;
this.price = _price; this.price = getPrice();
} }
...@@ -22,7 +22,17 @@ public class Engine { ...@@ -22,7 +22,17 @@ public class Engine {
} }
public Double getPrice() { public Double getPrice() {
if (this.getClass() == DieselEngine.class) {
return 2000d;
} else if (this.getClass() == ElectricEngine.class) {
return 1800d;
} else if (this.getClass() == HybridEngine.class) {
return 3000d;
} else if (this.getClass() == PetrolEngine.class) {
return 1400d;
} else {
return 0d;
}
} }
......
package Engine; package Engine;
public class HybridEngine { public class HybridEngine extends Engine {
public HybridEngine(String _cylindre, Double _price) {
super(_cylindre, _price);
this.type = EngineType.HYBRID;
}
public String toString() {
return "Hybrid Engine";
}
} }
package Engine; package Engine;
public class PetrolEngine { public class PetrolEngine extends Engine {
public PetrolEngine(String _cylindre, Double _price) {
super(_cylindre, _price);
this.type = EngineType.PETROL;
}
public String toString() {
return "Petrol Engine";
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment