Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jostein Ruen #56

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/main/java/com/booleanuk/core/Battery.java
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}
78 changes: 78 additions & 0 deletions src/main/java/com/booleanuk/core/Car.java
Original file line number Diff line number Diff line change
@@ -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());


}
}
24 changes: 24 additions & 0 deletions src/main/java/com/booleanuk/core/Controller.java
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}
77 changes: 77 additions & 0 deletions src/test/java/com/booleanuk/core/carTest.java
Original file line number Diff line number Diff line change
@@ -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());
}




}