Write Tests
Run Tests
FAIL
Implement
PASS
public class Tank {
// ...
private int direction;
// ...
// Construct a tank.
// effects: places tank at position (x, Y_POS) moving right.
public Tank(int x) {
this.x = x;
direction = 1;
}
// Faces tank to the right
// modifies: this
// effects: tank is facing right
public void faceRight() {
direction = 1;
}
// Faces tank to the left
// modifies: this
// effects: tank is facing left
public void faceLeft() {
direction = -1;
}
// ...
}
Maybe we could change how direction is implemented?
public class Cake {
//REQUIRES: !isBaked()
//MODIFIES: this
//EFFECTS: changes the status of
//the cake to baked
public void bake() { // stub }
//REQUIRES: isCool()
//MODIFIES: this
//EFFECTS: changes the status of the
//cake to decorated
public void decorate() { // stub }
//REQUIRES: isBaked()
//MODIFIES: this
//EFFECTS: changes the status of
//the cake to cool
public void cool() { // stub }
//EFFECTS: returns true if
//the cake is baked
public boolean isBaked() {
return false; // stub
}
//EFFECTS: returns true if
//the cake is cool
public boolean isCool() {
return false; // stub
}
}
We will finally implement it!!!