Assignment 8Due Oct 15, on line
Part of
the homework for CS:2820, Fall 2020
|
Thing t = new Thing(); t.method( (int i)-> i + 1 );
Here is a skeleton for class Thing:
class Thing { public interface Mystery { ????? } public void method( Mystery param ) { // body of method omitted } }
Which text below would work where ????? is given above:
a) void method( int i );
b) int method( int i );
c) abstract int method( int i );
d) abstract void method( int i );
e) private int method( int i );
Simulator.schedule( 8.0*hour, (double t)->w.open(t) );
The value 8.0*hour is passed as t to w.open(t)
through the following steps that are not given in order
(and some steps are omitted):
v) e is removed from eventSet.
w) 8.0*hour is put in e.time for some Event e.
x) w.open(t) is called.
y) e.act.trigger(e.time) is called.
z) e drifts to the head of eventSet.
What is the correct order for these steps?
a) vwyzx
b) xwyvz
c) ywzvx
d) wzvyx
e) zywvx
public void open(double time) { Simulator.schedule( time + 8*hour, ------- ); }
a) Add class Simulatior to your epidemic simulator.
b) Add a new input line to your model description file that specifies the end of time. For example, to simulate 10 days, you would say:
end 10.0;
c) At the beginning of time, you should schedule the end of time. Initially, since we have nothing special to do, just schedule a call to System.exit(0) at that time.
d) For each workplace, schedule it to open for the first time at 8:00 AM on day zero.
e) When a workplace is opened, it should print a debugging message saying Workplace XXX@XXX open at time XXX, and then it should schedule itself to close 8 hours later.
e) When a workplace is closed, it should print a debugging message saying Workplace XXX@XXX closed at time XXX, and then it should schedule itself to re-open 16 hours later. Ignore weekends!
Time output can be raw floating point numbers, no need to convert to days, hours, minutes and seconds. This is still debug output. It is worth asking, where should the constants for time units day hour and minute be declared? Your choice, but be sensible!
A student asked: Does that mean that the end time, on the input, is specified in days?
Yes. If the input file says end 7.5 that means 7 days and 12 hours.
A student asked: If hour is defined as day/24 and day=Double.intValue(time) does that mean that hour is not constant?
You are confusing day as a time unit, where it must be constant, with the day number, counting from the start of time, which changes. In software, the same identifier can have different meanings in different contexts.
A student asked: How do you schedule something to happen at a particular time of day.
These two examples illustrate scheduling an event at an absolute and a relative time:
Simulator.schedule( AbsoluteTime, (double t) -> SomeThing(t) ); Simulator.schedule( time + RelativeTime, (double t) -> SomeThing(t) );
For the problem at hand, the first opening of a business would be scheduled at an absolute time, 8AM on day zero, while all later openings and closings of that business would be scheduled at relative times, relative to the previous opening or closing.