SCLS APCS Lab
  • SCLS APCS LAB
  • 常见算法背诵
    • Week5
    • Week7
    • Week8
  • Methods
    • Lab1: Calculator
    • In-class Test
      • Multiple-Choices Questions
      • Lab2
      • Lab2 Answer
      • Homework
    • Strings HW
    • Lab3: String Magic
      • Lab3 Solution
  • If statements
    • Homework(Oct.13th)
    • Lab4: Chatbot I(Due Oct 23th)
    • Lab4: Chatbot II
  • Lab5: DNA
    • 完成情况
  • Lab6: Bus Stop
    • Solution
  • Hackathon I: Design Class
    • MCQ
    • Project I: AddtionPattern
    • Project II: Bank Account
    • Solution
  • Hackathon II: Array Algorithms
    • Algorithm
    • Solution
  • ArrayList & 2D Array
    • Project I: Bank
    • Project II: Transform Matrix
    • Solution
  • Inheritance
Powered by GitBook
On this page
  1. Lab6: Bus Stop

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;
    }      
}
PreviousLab6: Bus StopNextHackathon I: Design Class

Last updated 2 years ago