public class DotRace {
    private Dot redDot;
    private Dot blueDot; 
    private int goalDistance;
    
    public DotRace(int goal) {
        this.redDot = new Dot("red");
        this.blueDot = new Dot("blue");
        this.goalDistance = goal;
    }

    public int getRedPosition() {
        return this.redDot.getPosition();
    }
    
    public int getBluePosition() {
        return this.blueDot.getPosition();
    }   
    
    public int getGoalDistance() {
        return this.goalDistance;
    }   

    public void step() {
        if (this.getRedPosition() >= this.getGoalDistance() && 
                    this.getBluePosition() >= this.getGoalDistance()) {
            System.out.println("The race is over: it's a tie.");
        }
        else if (this.getRedPosition() >= this.getGoalDistance()) {
           System.out.println("The race is over: RED wins!");
        }
        else if (this.getBluePosition() >= this.getGoalDistance()) {
           System.out.println("The race is over: BLUE wins!");
        }
        else {
            this.redDot.step();
            this.blueDot.step();
        }
    }
          
    public void showStatus() {
        this.redDot.showPosition();    
        this.blueDot.showPosition();
    }
    
    public void reset() {
        this.redDot.reset();    
        this.blueDot.reset();
    }
}
