001package edu.pdx.cs410J.net; 002 003/** 004 * This class represents an employee of a <code>McDonalds</code> who 005 * makes BigMacs(tm). 006 */ 007public class McEmployee implements Runnable { 008 009 private String name; 010 private McDonalds mcDonalds; 011 012 /** 013 * Creates a new <code>McEmployee</code> 014 */ 015 public McEmployee(int id, McDonalds mcDonalds) { 016 this.name = "Employee " + id; 017 this.mcDonalds = mcDonalds; 018 } 019 020 /** 021 * Keep making BigMacs 022 */ 023 public void run() { 024 System.out.println(this.name + " arrives at work"); 025 026 while (this.mcDonalds.moreBigMacs()) { 027 System.out.println(this.name + " starts a BigMac"); 028 029 // It takes time to cook a BigMac 030 long wait = (long) (Math.random() * 10000); 031 try { 032 Thread.sleep(wait); 033 034 } catch (InterruptedException ex) { 035 return; 036 } 037 038 System.out.println(this.name + " finishes a BigMac"); 039 040 synchronized(this.mcDonalds) { 041 this.mcDonalds.notify(); 042 } 043 } 044 } 045 046}