Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 9cef04192e
Fetching contributors…

Cannot retrieve contributors at this time

83 lines (63 sloc) 1.325 kB
import edu.ucdavis.jr.*;
import java.util.*;
public abstract class Person {
private Door door;
protected int numCalls;
private String name;
public op void tellLastCallOrClosing();
@Override
public String toString()
{
return name;
}
public Person(String name)
{
this.name = name;
}
public Person()
{
this("Unnamed");
}
public void say(String msg)
{
Clock clock = Global.clock;
if(clock != null)
System.out.println(Global.clock.getTime() + ": " + name + " says: " + msg);
}
private boolean enterDoor()
{
numCalls = Global.door.add(this);
return numCalls < 2;
}
private void leaveBar()
{
call Global.door.leave(this);
}
public boolean knowsItsClosed()
{
return numCalls >= 2;
}
public boolean knowsLastCallHasBeen()
{
return numCalls >= 1;
}
protected abstract boolean shouldGoHome();
protected abstract void oneIteration();
public process personProcess
{
say("I'm going in ...");
if( enterDoor())
{
startLoop();
say("I'm going home ...");
leaveBar();
}
}
private void startLoop()
{
while(!shouldGoHome())
{
oneIteration();
}
}
}
Jump to Line
Something went wrong with that request. Please try again.