Solution

public class Bus{
    private int busStops;
    private int currentStop = 1;
    private int direction=1;
    
    public Bus(int s){
        busStops = s;
    }    
    public void move(){
        currentStop += direction;
        if (currentStop == busStops){
            direction = -1;
        }
        if (currentStop == 1){
            direction = 1;
        }
    }
    public int getCurrentStop(){
        return currentStop;
    }      
}

Last updated