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

Car.toString() && Car.decelerate() w/Tests #37

Open
wants to merge 8 commits into
base: master
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin/*.class
.DS_Store
/bin/
Binary file added bin/Car.class
Binary file not shown.
Binary file added bin/CarTest.class
Binary file not shown.
7 changes: 5 additions & 2 deletions src/Car.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ public void accelerate(int amount){
}
}

public void decelerate(int amount) {
speed -= speed-amount < 0 ? speed : amount;
}

/**
* 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);
}
}
14 changes: 13 additions & 1 deletion test/CarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ public void canDoToString(){
}

// Create and pass test for deceleration.
@Test
public void canDecelerate() {
Car car1 = new Car("Red", 100);
car1.accelerate(100);
car1.decelerate(5);
assertThat(car1.getSpeed(), is(95));
}

// Create and pass test for no deceleration below 0.

@Test
public void cannotDeceleratePastZero() {
Car car1 = new Car("Red", 100);
car1.decelerate(5);
assertThat(car1.getSpeed(), is(0));
}
}