Last active
November 19, 2015 06:03
-
-
Save LOZORD/3d730ac46f6ea9246e04 to your computer and use it in GitHub Desktop.
The programmatic representation of whether or not you are a Badger who takes WildHacks by storm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Whether Passenger p (you) can get on the bus at Time t | |
public boolean attemptToGetOnBus(Passenger p, Time t) throws HustleError { | |
if (!p.location().equal("CS Building")) { | |
return false; // what are you doing, kiddo? | |
} else if (!p.isRegisteredForWildHacks()) { | |
return false; | |
} | |
Time startTime = Time.earliestOf(LEO.arrival(), Time.FIVE_THIRTY); | |
if (!t.isBetween(startTime, Time.SIX_SHARP)) { | |
return false; | |
} | |
// Now for the interesting part... | |
if (p.hasBusTicket()) { | |
if (t.isBefore(Time.FIVE_FIFTY)) { | |
return true; // welcome aboard! | |
} else { | |
// run! there may still be a seat for you! | |
throw new HustleError(); | |
} | |
} else if (p.isWaitlisted()) { | |
if (t.isBefore(Time.FIVE_FIFTY)) { | |
this.waitListQueue().enqueue(p); | |
p.waitUntil(Time.FIVE_FIFTY); | |
} else { | |
if (this.hasSeatsOpen() && this.waitListQueue().peek().equals(p)) { | |
this.waitListQueue.dequeue(); | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
} else { | |
return false; // wat? | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment