Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8ba9c7c
Scania småsaker
tomrex1 Nov 10, 2023
4c7166f
Merge pull request #2 from GitoPot/Tom
tomrex1 Nov 10, 2023
fcb5059
Scania
Alex04412 Nov 10, 2023
e2dfa94
Merge branch 'master' into sin(g)/cos(g)
Alex04412 Nov 10, 2023
9de2198
Merge pull request #3 from GitoPot/sin(g)/cos(g)
Alex04412 Nov 10, 2023
9145f57
Merge pull request #4 from GitoPot/Anders
GitoPot Nov 10, 2023
5e4f421
biltransport
GitoPot Nov 10, 2023
560fd32
Scania increment/decrement Speed implemented.
Alex04412 Nov 10, 2023
d592587
Merge pull request #5 from GitoPot/Anders
GitoPot Nov 10, 2023
209509f
Merge pull request #6 from GitoPot/sin(g)/cos(g)
GitoPot Nov 10, 2023
cc3f857
TestScania gradient
tomrex1 Nov 13, 2023
abe71fb
Transporter
GitoPot Nov 13, 2023
40cd91a
Merge pull request #7 from GitoPot/Anders2
GitoPot Nov 13, 2023
e6e696f
Merge pull request #8 from GitoPot/Tom
GitoPot Nov 13, 2023
27ce4cd
Transporter ramp fix
GitoPot Nov 13, 2023
6a1ed1f
Merge pull request #9 from GitoPot/Anders
GitoPot Nov 13, 2023
384a867
Tranport addCarToLoad implementation
Alex04412 Nov 13, 2023
203d31b
Tranport addCarToLoad implementation
Alex04412 Nov 13, 2023
3dd55d0
Merge pull request #10 from GitoPot/Tang
GitoPot Nov 13, 2023
59f781a
Move if-sats
tomrex1 Nov 15, 2023
8b57d01
add gas to movable test
Alex04412 Nov 15, 2023
d60ec31
Merge pull request #11 from GitoPot/Tom
GitoPot Nov 15, 2023
cc30e65
Merge pull request #12 from GitoPot/Tang
GitoPot Nov 15, 2023
95d7d3f
Start of composition and delegation
GitoPot Nov 15, 2023
d169eff
Start of composition and delegation
GitoPot Nov 15, 2023
e2ae5fd
Helper file, to fix composition problem
GitoPot Nov 15, 2023
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
48 changes: 29 additions & 19 deletions Cars.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ public abstract class Cars implements Movable{
protected double currentSpeed; // The current speed of the car
private Color color; // Color of the car
private final String modelName; // The car model name
private int loadSize;

protected double x;
protected double y;
private double x;
private double y;
private int direction;

protected Cars(int carNrDoors, double carEnginePower, Color carColor, String carModelName){
protected Cars(int carNrDoors, double carEnginePower, Color carColor, String carModelName, int carLoadSize){
nrDoors = carNrDoors;
enginePower = carEnginePower;
color = carColor;
modelName = carModelName;


loadSize=carLoadSize;
x=0;
y=0;
stopEngine();
}

Expand Down Expand Up @@ -52,6 +54,10 @@ protected void stopEngine(){
currentSpeed = 0;
}

public int getLoadSize(){
return loadSize;
}

abstract protected void incrementSpeed(double amount);
abstract protected void decrementSpeed(double amount);

Expand Down Expand Up @@ -79,23 +85,21 @@ protected void brake(double amount){

@Override
public void move() {
if (direction%2==0) {
if (direction==0){
y=y+currentSpeed;
}
else {
y=y-currentSpeed;
}
if (direction==0){
y=y+currentSpeed;
}
else if(direction==2) {
y=y-currentSpeed;
}
else {
if (direction==1){
x=x+currentSpeed;
}
else {
x=x-currentSpeed;
}

else if (direction==1){
x=x+currentSpeed;
}
else if(direction==3) {
x=x-currentSpeed;
}


System.out.println("X: "+x);
System.out.println("Y: "+y);
}
Expand All @@ -116,4 +120,10 @@ public void turnRight() {
direction=direction-4;
}
}
public double getX(){
return x;
}
public double getY(){
return y;
}
}
6 changes: 6 additions & 0 deletions GenericGarage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public interface GenericGarage {
//Ta imot bilar tills parkeringen är full
//fixa bilar?
//hämta bilar
default void test(){}
}
7 changes: 7 additions & 0 deletions HelperGarage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class HelperGarage implements GenericGarage{

@Override
public void test() {

}
}
11 changes: 11 additions & 0 deletions LosSantosCustoms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class LosSantosCustoms implements GenericGarage{//uppgift 3
// Detta är vår bilverkstads fil

// Det behövs skapa en gemensam fil som olika verkstäder kan "ärva" från genom composition, det går inte att ärva normalt.
private final HelperGarage parent = new HelperGarage(); // Composition

@Override
public void test() {
parent.test(); // Delegation
}
}
2 changes: 1 addition & 1 deletion Saab95.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class Saab95 extends Cars{
private boolean turboOn;
public Saab95(){
super(2, 125, Color.red, "Saab95");
super(2, 125, Color.red, "Saab95", 1);
turboOn = false;
}
public void setTurboOn(){
Expand Down
39 changes: 37 additions & 2 deletions Scania.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
public class Scania {
//Kolla vad duktig Anders har varit
import java.awt.*;

public class Scania extends Cars{

private double gradiant;


public Scania(){
super(2,100, Color.BLUE, "Scania", 2);
gradiant=0;
}

@Override
protected void incrementSpeed(double amount){
if(gradiant == 0){
currentSpeed = Math.min(getCurrentSpeed() + amount, getEnginePower());
}
}
@Override
protected void decrementSpeed(double amount){
if(currentSpeed <= amount){
currentSpeed = 0;
}else{
currentSpeed = getCurrentSpeed() - amount;
}
}


protected void changeGradiant(double newGradiant){
if (this.getCurrentSpeed() == 0 && newGradiant<=70 && newGradiant>=0){
gradiant=newGradiant;
}
}
public double getGradiant(){
return gradiant;
}
}

62 changes: 62 additions & 0 deletions Transport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.lang.Math.*;

public class Transport extends Cars{
private boolean ramp;
private List<Cars> carLoad;

private int maxLoad;

public Transport(int maximunLoad){
super(2,100, Color.yellow, "Jumper EH35L HDI", 2);
ramp=false;
maxLoad=maximunLoad;
carLoad = new ArrayList<Cars>();
}

@Override
protected void incrementSpeed(double amount){
if(!ramp){
currentSpeed = Math.min(getCurrentSpeed() + amount, getEnginePower());
}
}
@Override
protected void decrementSpeed(double amount){
if(currentSpeed <= amount){
currentSpeed = 0;
}else{
currentSpeed = getCurrentSpeed() - amount;
}
}


protected void changeRamp(){
if (this.getCurrentSpeed() == 0 && !ramp){
ramp = true;
}else {
ramp = false;
}
}
public boolean getRamp(){
return ramp;
}

public List<Cars> getCarLoad(){
return carLoad;
}

protected void addCarToLoad(Cars Car){ //antag att Transporten bara kan lasta personbilar
int loadSize = Car.getLoadSize();
double diffX = this.getX()-Car.getX();
double diffY = this.getY()-Car.getY();
if ((Math.abs(diffX)<=5) && (Math.abs(diffY)<=5) ) {
if (loadSize < 2 && this.getCurrentSpeed() == 0 && maxLoad > carLoad.size() && ramp) {
carLoad.add(Car);
}
}
}


}
2 changes: 1 addition & 1 deletion Volvo240.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Volvo240 extends Cars {


public Volvo240() {
super(4, 100, Color.black, "Volvo240");
super(4, 100, Color.black, "Volvo240", 1);
}

private double speedFactor() {
Expand Down
5 changes: 3 additions & 2 deletions test/TestSaab.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,18 @@ public void testSetColor(){

@Test
public void testMovable(){//testar även turn funtionerna
saab.gas(1);
saab.move();
saab.turnLeft();
saab.move();
saab.turnLeft();
saab.move();
System.out.println("x "+saab.x +" y "+saab.y);
System.out.println("x "+saab.getX() +" y "+saab.getY());
saab.turnRight();
saab.turnRight();
saab.turnRight();
saab.move();
assertTrue(saab.y==0 && saab.x==0);
assertTrue(saab.getY()==0 && saab.getX()==0);

}

Expand Down
17 changes: 13 additions & 4 deletions test/TestScania.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -34,7 +35,7 @@ public void testGasAndBrake(){

@Test
public void testGetModelName(){
String name = "Scania";
String name = "ScaniaTruck";
assertEquals(scan.getModelName(), name);
}

Expand Down Expand Up @@ -68,20 +69,28 @@ public void testSetColor(){

@Test
public void testMovable(){//testar även turn funtionerna
scan.gas(1);
scan.move();
scan.turnLeft();
scan.move();
scan.turnLeft();
scan.move();
System.out.println("x "+scan.x +" y "+scan.y);
System.out.println("x "+scan.getX() +" y "+scan.getY());
scan.turnRight();
scan.turnRight();
scan.turnRight();
scan.move();
assertTrue(scan.y==0 && scan.x==0);
assertTrue(scan.getY()==0 && scan.getX()==0);

}

}
@Test
public void testChangeGradient(){
scan.changeGradiant(67);
scan.changeGradiant(0);
scan.gas(1);
scan.changeGradiant(10);
assertTrue(scan.getGradiant() == 0);
}

}
33 changes: 33 additions & 0 deletions test/TestTransport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import org.junit.Before;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertTrue;

public class TestTransport {
private Transport transport;
private Saab95 saab;
private Volvo240 volvo;
@Before
public void init(){
transport = new Transport(2);
saab = new Saab95();
volvo = new Volvo240();
}

@Test
public void testAddCardToLoad(){


transport.addCarToLoad(saab);
List<Cars> carLoad = transport.getCarLoad();
transport.changeRamp();
transport.addCarToLoad(volvo);
transport.addCarToLoad(saab);
transport.addCarToLoad(saab);

assertTrue(carLoad.size()==2);
}

}
5 changes: 3 additions & 2 deletions test/TestVolvo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ public void testDecrementSpeed(){

@Test
public void testMovable(){//testar även turn funtionerna
volvo.gas(1);
volvo.move();
volvo.turnLeft();
volvo.move();
volvo.turnLeft();
volvo.move();
System.out.println("x "+volvo.x +" y "+volvo.y);
System.out.println("x "+volvo.getX() +" y "+volvo.getY());
volvo.turnRight();
volvo.turnRight();
volvo.turnRight();
volvo.move();
assertTrue(volvo.y==0 && volvo.x==0);
assertTrue(volvo.getY()==0 && volvo.getX()==0);

}

Expand Down