/** This dev asks a question to the Team Lead */ private void askQuestion() { System.out.println( TimeTracker.currentTimeToString() + ": " + getName() + " is asking a question"); this.teamLead.requestAnswerForQuestion(this); System.out.println( TimeTracker.currentTimeToString() + ": " + getName() + "'s question was answered."); }
/** Simulation for this thread to run through 1 work day */ public void run() { Random rand = new Random(); try { super.run(); // Wait for up to 30 mins elapseTime(rand.nextInt(TimeHelp.HALF_HOUR.ms() + 1)); /*-------ARRIVE AT WORK-------*/ System.out.printf( "%s: %s has arrived to the workplace\n", TimeTracker.currentTimeToString(), getName()); /*--------WAIT UNTIL TEAM MEETING-------*/ teamLead.arriveForMeeting(); // Wait until meeting while (!teamLead.isInConferenceRoom()) { elapseTime(TimeHelp.MINUTE.ms()); } conferenceRoom.arriveInRoom(true); elapseTime(TimeHelp.FIFTEEN_MINUTES.ms()); logMeetingTime(TimeHelp.FIFTEEN_MINUTES.ms()); System.out.printf( "%s: %s is leaving Team Meeting\n", TimeTracker.currentTimeToString(), getName()); /*--------WAIT UNTIL LUNCH BREAK-------*/ System.out.printf( "%s: %s is developing until lunch break.\n", TimeTracker.currentTimeToString(), getName()); // Wait until lunch while (TimeTracker.getCurrentTime() < TimeHelp.HOUR.ms() * 4) { int probability = rand.nextInt(5); if (probability == 1) { askQuestion(); } logWorkingTime(TimeHelp.MINUTE.ms()); elapseTime(TimeHelp.MINUTE.ms()); } /*--------LUNCH BREAK-------*/ System.out.println(TimeTracker.currentTimeToString() + ": " + getName() + " goes on lunch."); int breakTime = (int) ((Math.random() * TimeHelp.HALF_HOUR.ms()) + TimeHelp.HALF_HOUR.ms()); elapseTime(breakTime); // Eat lunch for 30-60 minutes System.out.println( TimeTracker.currentTimeToString() + ": " + getName() + " finished eating lunch."); logLunchBreakTime(breakTime); /*--------WAIT UNTIL 4pm MEETING-------*/ System.out.printf( "%s: %s is developing until the all hands meeting.\n", TimeTracker.currentTimeToString(), getName()); while (TimeTracker.getCurrentTime() < (TimeHelp.HOUR.ms() * 8)) { // If it isn't 4pm yet,\ int probability = rand.nextInt(100); if (probability == 1) { askQuestion(); } logWorkingTime(TimeHelp.MINUTE.ms()); Thread.sleep(TimeHelp.MINUTE.ms()); // Wait a minute } System.out.printf( "%s: %s is going to the all hands meeting\n", TimeTracker.currentTimeToString(), getName()); conferenceRoom.arriveInRoom(false); elapseTime(TimeHelp.FIFTEEN_MINUTES.ms()); logMeetingTime(TimeHelp.FIFTEEN_MINUTES.ms()); System.out.printf( "%s: %s has left the all hands meeting.%n", TimeTracker.currentTimeToString(), getName()); System.out.printf( "%s: %s is developing for the rest of the day\n", TimeTracker.currentTimeToString(), getName()); int remainingWorkTime = (int) ((Math.random() * 45) + 1); elapseTime(remainingWorkTime * TimeHelp.MINUTE.ms()); System.out.printf( "%s: %s has left work for the day\n", TimeTracker.currentTimeToString(), getName()); } catch (InterruptedException | BrokenBarrierException e) { e.printStackTrace(); } }
public static void main(String[] args) { TimeTracker tt = new TimeTracker(10000); tt.start(); }