Skip to content
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
11 changes: 10 additions & 1 deletion src/Car.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,22 @@ public void accelerate(int amount){
}
}

public void decelerate(int amount){
int reducedSpeed = speed - amount;
if(amount <= speed){
speed = reducedSpeed;
}else{
speed = 0;
}
}

/**
* Displays the object as a string in the format
* "Color: red, Speed: 100"
* @return string representation of object.
*/
public String toString(){
// not implemented!
return("");
return("Color: " + color + ", Speed: " + speed + "");
}
}
16 changes: 15 additions & 1 deletion test/CarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,21 @@ public void canDoToString(){
}

// Create and pass test for deceleration.

@Test
public void canDecelerate(){
Car car1 = new Car("Red", 100);
car1.accelerate(50);
car1.decelerate(20);
assertThat(car1.getSpeed(), is(30));
}
// Create and pass test for no deceleration below 0.

@Test
public void noDecelerateBelowZero(){
Car car1 = new Car("Red", 100);
car1.accelerate(20);
car1.decelerate(30);
assertThat(car1.getSpeed(), is(0));
}

}