Skip to content

Instantly share code, notes, and snippets.

@kchodorow
Created March 31, 2015 20:46
Show Gist options
  • Save kchodorow/d908c1cea4f80b828dd1 to your computer and use it in GitHub Desktop.
Save kchodorow/d908c1cea4f80b828dd1 to your computer and use it in GitHub Desktop.
Train skeleton
public class SubwayLine {
public static void main(String[] args) {
Train local = new Train("C", 1, 16);
Train express = new Train("A", 3, 0);
for (int i = 0; i < 10; ++i) {
System.out.println("local: " + local.nextStop());
System.out.println("express: " + express.nextStop());
}
}
}
class Train {
private String name;
private int numStationsBetweenStops;
private int currentStation;
public Train(String inputName, int inputNumStations,
int startingStation) {
name = inputName;
numStationsBetweenStops = inputNumStations;
currentStation = startingStation;
}
public int nextStop() {
currentStation = currentStation + numStationsBetweenStops;
if (currentStation >= 20) {
currentStation = 20;
}
return currentStation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment