Commit 03eab045 authored by Arthur POIGNONNEC's avatar Arthur POIGNONNEC

[DEV] Création du constructeur de vehicle

+ Enumérations définissant les propriétés d'un véhicule
+ Ajout classes Door/Window/Frame/....
parent bc7f1c64
package garage;
public class TestBench {
}
package vehicle;
public abstract class Vehicle {
import vehicle.part.brake.Brake;
import vehicle.part.engine.Engine;
import vehicle.part.frame.Frame;
import vehicle.part.gearbox.GearBox;
import vehicle.part.gearbox.GearBoxAutomatic;
import vehicle.part.gearbox.GearBoxManual;
import vehicle.part.pedal.Pedal;
import vehicle.part.pedal.PedalAccelerator;
import vehicle.part.pedal.PedalBrake;
import vehicle.part.pedal.PedalClutch;
import java.util.List;
public class Vehicle {
private Double price;
private String name;
private Brand brand;
private VehicleBrand brand;
// Parts
private Frame frame;
private List<Pedal> pedals;
private GearBox gearBox;
private List<Brake> brakes;
private Engine engine;
// Physic
private Double velocity;
public Vehicle(VehicleModel model){
brand = model.getBrand();
name = model.getName();
// CREATING FRAME
frame = new Frame(model.getFrameType());
// CREATING ENGINE
engine = new Engine("", 0d); // TODO Reprendre constructeur engine
private Double weight;
private Double length;
private Double width;
// CREATING gearBox
if("MANUAL".equals(model.getEngineModel().getGearBoxType())){
gearBox = new GearBoxManual(model.getEngineModel().getMaxGear());
}else {
gearBox = new GearBoxAutomatic(model.getEngineModel().getMaxGear());
}
public Vehicle() {
// CREATING BRAKES
for(Integer i = 0; i < model.getNbOfWheels(); i++ ){
brakes.add(new Brake(model.getBrakesType()));
}
// CREATING PEDALS
pedals.add(new PedalAccelerator(engine));
pedals.add(new PedalBrake(brakes));
if("MANUAL".equals(model.getEngineModel().getGearBoxType())) {
pedals.add(new PedalClutch((GearBoxManual) gearBox));
}
}
// METHODS
// METHODS /////////////////////////////////////////////////////////////////////////////////////////////////////////
// Print the name of the car with the options and the price.
// public String toString()
......@@ -24,11 +71,27 @@ public abstract class Vehicle {
// public void addOption(opt : vehicle.part.option)
// GETTER
// GETTER //////////////////////////////////////////////////////////////////////////////////////////////////////////
public Double getHeight(){
return frame.getHeight();
}
public Double getWidth(){
return frame.getWidth();
}
public Double getLength(){
return frame.getLength();
}
public Double getweight(){
return frame.getWeight();
}
// Get the brand of the car
// public Brand getBrand()
// public VehicleBrand getBrand()
// Get the options of the car
// public List<vehicle.part.option> getOptions()
......
package vehicle;
public enum Brand {
public enum VehicleBrand {
RENAULT("Renault"),
PEUGEOT("Peugeot"),
CITROEN("Citroen");
CITROEN("Citroen"),
FIAT("Fiat");
private final String value;
Brand(String value) {
VehicleBrand(String value) {
this.value = value;
}
......@@ -17,7 +18,7 @@ public enum Brand {
}
public static boolean contains(String value) {
for (Brand brand : Brand.values()) {
for (VehicleBrand brand : VehicleBrand.values()) {
if (brand.getValue().equals(value)) {
return true;
}
......
package vehicle;
import vehicle.part.brake.BrakeType;
import vehicle.part.engine.EngineModel;
import vehicle.part.frame.FrameType;
public enum VehicleModel {
FIAT500(VehicleBrand.FIAT, "500", EngineModel.TDI_A_D, FrameType.MICRO, BrakeType.PAD_FX200, 4);
private final VehicleBrand brand;
private final String name;
private final EngineModel engineModel;
private final FrameType frameType;
private final BrakeType brakesType;
private final Integer nbOfWheels;
VehicleModel(VehicleBrand brand, String name, EngineModel engineModel, FrameType frameType, BrakeType brakesType, Integer nbOfWheels){
this.brand = brand;
this.name = name;
this.engineModel = engineModel;
this.frameType = frameType;
this.brakesType = brakesType;
this.nbOfWheels = nbOfWheels;
}
public VehicleBrand getBrand() {
return brand;
}
public String getName() {
return name;
}
public EngineModel getEngineModel() {
return engineModel;
}
public FrameType getFrameType() {
return frameType;
}
public BrakeType getBrakesType() {
return brakesType;
}
public Integer getNbOfWheels() {
return nbOfWheels;
}
}
package vehicle.part.door;
public class Door {
private Window window;
}
package vehicle.part.door;
public class Window {
}
package vehicle.part.engine;
import vehicle.part.gearbox.Gear;
public enum EngineModel {
TDI_M_D(EngineType.DIESEL, "MANUAL", Gear.FIFTH, 200d, 2000d, 300d),
TDI_A_D(EngineType.DIESEL, "AUTOMATIC", Gear.FIFTH, 200d, 2500d, 300d),
TDI_A_P(EngineType.PETROL, "AUTOMATIC", Gear.FIFTH, 200d, 2300d, 300d);
private final EngineType engineType;
private final String gearBoxType;
private final Gear maxGear;
private final Double cylindre;
private final Double price;
private final Double weight;
EngineModel(EngineType engineType, String gearBoxType, Gear maxGear, Double cylindre, Double price, Double weight){
this.engineType = engineType;
this.gearBoxType = gearBoxType;
this.maxGear = maxGear;
this.cylindre = cylindre;
this.price = price;
this.weight = weight;
}
public EngineType getEngineType() {
return engineType;
}
public String getGearBoxType() {
return gearBoxType;
}
public Gear getMaxGear() {
return maxGear;
}
public Double getCylindre() {
return cylindre;
}
public Double getPrice() {
return price;
}
public Double getWeight() {
return weight;
}
}
package vehicle.part.frame;
import vehicle.part.door.Door;
import java.util.List;
public class Frame {
private Double weight;
private Double length;
private Double width;
private Double height;
private List<Door> doors;
public Frame(FrameType type) {
weight = type.getWeigth();
length = type.getLength();
width = type.getWidth();
height = type.getHeight();
for(Integer i = 0; i < type.getNbOfDoors(); i++) doors.add(new Door());
}
public Double getWeight() {
return weight;
}
public Double getLength() {
return length;
}
public Double getWidth() {
return width;
}
public Double getHeight() {
return height;
}
public List<Door> getDoors() {
return doors;
}
}
package vehicle.part.frame;
public enum FrameType {
MICRO(2.5, 2.0, 1.7, 800d, 2),
SEDAN(2.5, 2.0, 1.7, 800d, 2),
SUV(2.5, 2.0, 1.7, 800d, 2),
ROADSTER(2.5, 2.0, 1.7, 800d, 2),
PICKUP(2.5, 2.0, 1.7, 800d, 2),
COUPE(2.5, 2.0, 1.7, 800d, 2),
SUPERCAR(2.5, 2.0, 1.7, 800d, 2),
CABRIOLET(2.5, 2.0, 1.7, 800d, 2),
MINIVAN(2.5, 2.0, 1.7, 800d, 2),
TRUCK(2.5, 2.0, 1.7, 800d, 2),
MINITRUCK(2.5, 2.0, 1.7, 800d, 2);
private final Double length;
private final Double width;
private final Double height;
private final Double weigth;
private final Integer nbOfDoors;
FrameType(Double length, Double width, Double height, Double weigth, Integer nbOfDoors){
this.length = length;
this.width = width;
this.height = height;
this.weigth = weigth;
this.nbOfDoors = nbOfDoors;
}
public Double getLength() {
return length;
}
public Double getWidth() {
return width;
}
public Double getHeight() {
return height;
}
public Double getWeigth() {
return weigth;
}
public Integer getNbOfDoors() {
return nbOfDoors;
}
}
......@@ -9,7 +9,8 @@ public enum Gear {
THRID(3),
FORTH(4),
FIFTH(5),
SIXTH(6);
SIXTH(6),
AUTO(10);
private final Integer value;
......
package vehicle.part.gearbox;
import java.util.Arrays;
public class GearBoxAutomatic implements GearBox {
private Gear currentGear;
private Gear maxGear;
public GearBoxAutomatic(Gear maxGear) {
this.maxGear = maxGear;
this.currentGear = Gear.NEUTRAL;
}
@Override
public void gearUp() {
if (!currentGear.equals(maxGear)) {
currentGear = Gear.getEnum(currentGear.getValue() + 1);
}
}
@Override
public void gearDown() {
if (!currentGear.equals(Gear.REVERSE)) {
currentGear = Gear.getEnum(currentGear.getValue() - 1);
}
}
public void automatic(){
}
@Override
public void neutral() {
if(Arrays.asList(Gear.REVERSE, Gear.AUTO).contains(currentGear)){
currentGear = Gear.NEUTRAL;
}
}
@Override
public void reverse() {
if(Arrays.asList(Gear.NEUTRAL, Gear.AUTO).contains(currentGear)){
currentGear = Gear.REVERSE;
}
}
}
......@@ -7,6 +7,10 @@ public class PedalAccelerator implements Pedal{
private Engine engine;
private Double state;
public PedalAccelerator(Engine engine) {
this.engine = engine;
this.state = state;
}
@Override
public void setState(Double pressure) {
......
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