diff --git a/Model.png b/Model.png new file mode 100644 index 0000000..5b6dff5 Binary files /dev/null and b/Model.png differ diff --git a/src/main/java/com/booleanuk/core/Battery.java b/src/main/java/com/booleanuk/core/Battery.java new file mode 100644 index 0000000..9d106c6 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Battery.java @@ -0,0 +1,35 @@ +package com.booleanuk.core; + +public class Battery { + int percentage; + String batteryType; + + public Battery(String batteryType) { + this.percentage = 100; + this.batteryType = batteryType; + } + + public int getPercentage() { + return percentage; + } + + public void setPercentage(int percentage){ + this.percentage = percentage; + } + + public String getBatteryType() { + return batteryType; + } + + public void setBatteryType(String batteryType) { + this.batteryType = batteryType; + } + + @Override + public String toString() { + return "Battery{" + + "percentage=" + percentage + + ", batteryType='" + batteryType + '\'' + + '}'; + } +} diff --git a/src/main/java/com/booleanuk/core/Car.java b/src/main/java/com/booleanuk/core/Car.java new file mode 100644 index 0000000..04cb1e9 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Car.java @@ -0,0 +1,78 @@ +package com.booleanuk.core; + +import javax.naming.ldap.Control; + +public class Car { + String color; + Battery battery; + Controller controller; + + public Car(String color, Battery battery, Controller controller){ + this.color=color; + this.battery=battery; + this.controller = controller; + } + + public String moveForward(){ + this.battery.setPercentage(this.battery.getPercentage()-1); + return "Car moved forward"; + } + + public String moveLeft(){ + this.battery.setPercentage(this.battery.getPercentage()-1); + return "Car turned left"; + } + + public String moveRight(){ + this.battery.setPercentage(this.battery.getPercentage()-1); + return "Car turned right"; + } + + public String stopCar(){ + return "Car stopped"; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public Battery getBattery() { + return battery; + } + + public void setBattery(Battery battery) { + this.battery = battery; + } + + public Controller getController() { + return controller; + } + + public void setController(Controller controller) { + this.controller = controller; + } + + @Override + public String toString() { + return "Car{" + + "color='" + color + '\'' + + ", battery=" + battery + + ", controller=" + controller + + '}'; + } + + //sanity check + public static void main(String[] args) { + Car car = new Car("Blue", new Battery("Disposable"), new Controller("Advanced")); + + System.out.println(car); + + System.out.println(car.moveRight()); + + + } +} diff --git a/src/main/java/com/booleanuk/core/Controller.java b/src/main/java/com/booleanuk/core/Controller.java new file mode 100644 index 0000000..cba3f02 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Controller.java @@ -0,0 +1,24 @@ +package com.booleanuk.core; + +public class Controller { + private String controllerType; + + public Controller(String controllerType) { + this.controllerType = controllerType; + } + + public String getControllerType() { + return controllerType; + } + + public void setControllerType(String controllerType) { + this.controllerType = controllerType; + } + + @Override + public String toString() { + return "Controller{" + + "controllerType='" + controllerType + '\'' + + '}'; + } +} diff --git a/src/test/java/com/booleanuk/core/carTest.java b/src/test/java/com/booleanuk/core/carTest.java new file mode 100644 index 0000000..cb15e6a --- /dev/null +++ b/src/test/java/com/booleanuk/core/carTest.java @@ -0,0 +1,77 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class carTest { + + @Test + public void changeColorTest(){ + Car car = new Car("Blue", new Battery("Disposable"), new Controller("Advanced")); + car.setColor("Red"); + + Assertions.assertEquals("Red", car.getColor()); + } + + @Test + public void setBatteryTypeTest(){ + Car car = new Car("Blue", new Battery("Disposable"), new Controller("Advanced")); + car.getBattery().setBatteryType("Rechargable"); + + Assertions.assertEquals("Rechargable", car.getBattery().getBatteryType()); + } + + @Test + public void setControllTypeTest(){ + Car car = new Car("Blue", new Battery("Disposable"), new Controller("Advanced")); + car.getController().setControllerType("Simple"); + + Assertions.assertEquals("Simple", car.getController().getControllerType()); + } + + @Test + public void checkBatteryTest(){ + Car car = new Car("Blue", new Battery("Disposable"), new Controller("Advanced")); + + + Assertions.assertEquals(100, car.getBattery().getPercentage()); + } + + @Test + public void moveForwardTest(){ + Car car = new Car("Blue", new Battery("Disposable"), new Controller("Advanced")); + + + Assertions.assertEquals("Car moved forward", car.moveForward()); + } + + @Test + public void moveLeftTest(){ + Car car = new Car("Blue", new Battery("Disposable"), new Controller("Advanced")); + + + Assertions.assertEquals("Car turned left", car.moveLeft()); + } + + @Test + public void moveRightTest(){ + Car car = new Car("Blue", new Battery("Disposable"), new Controller("Advanced")); + + + Assertions.assertEquals("Car turned right", car.moveRight()); + } + + @Test + public void changeBatteryTest(){ + Car car = new Car("Blue", new Battery("Disposable"), new Controller("Advanced")); + car.moveForward(); + car.setBattery(new Battery("Disposable")); + + + Assertions.assertEquals(100, car.getBattery().getPercentage()); + } + + + + +}