Assignment 11

Due Nov 5, on line

Part of the homework for CS:2820, Fall 2020
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Simple multiple choice questions, 1 point each:

Here is a bit of Java code from class Person in the reference soluton to MP8. Several of the questions below are about this code.

private void beInfectious( double time ) {
    numLatent = numLatent - 1;
    infectionState = States.infectious;
    numInfectious = numInfectious + 1;
    if (place != null) place.oneMoreInfectious( time );
    if (rand.nextFloat() > bedriddenProb) { // person stays asymptomatic
        double delay = rand.nextLogNormal( infectRecMedT, infectRecScatT );
        Simulator.schedule( delay + time, (double t)-> beRecovered( t ) );
    } else { // person becomes bedridden
        double delay = rand.nextLogNormal( infectBedMedT, infectBedScatT );
        Simulator.schedule( delay + time, (double t)-> beBedridden( t ) );

  1. In the above code, without looking outside the above code, we can conclude that the variable numInfectious is probably declared as ...
    a) final.
    b) an instance variable.
    c) private.
    d) int.
    e) public

  2. In the above code, the test for place not null is required in order to prevent ...
    a) an exception from being thrown.
    b) a person from being in two places at once.
    c) a person from changing state when in transit between places.
    d) a person from being counted twice in the same place.
    e) None of the above

  3. In the above code, we schedule one of two things, either a call to beBedridden() or beRecovered().
    a) These must be instance methods of class Person.
    b) These must be static methods of class Person.
    c) These must be instance methods of class Place.
    d) These must be static methods of class Place.
    e) None of the above

  4. In Java, when a person enters state dead, we can immediately remove that person from the list of occupants in their current place (if any), the list of residents in their home, and the list of employees at their workplace. If we do this, the person still has a risk of being resurrected because:
    a) an exception could occur.
    b) this person might have a pending change of disease state.
    c) an event might have been scheduled involving this person.
    d) all of the above.
    e) none of the above.

  5. In Java, a%b differs from a(mod b) as traditionally defined by mathematicians when
    a) b is negative and a%b is zero.
    b) true = false (that is, never).
    c) a is negative and a%b is zero.
    d) a/(-b) differs from (-a)/b.
    e) a or b is negative and a%b is nonzero.

Machine Problem 9 -- due Monday, Nov 9

Break the reference solution to MP8 into separate files, one per class, and make sure it still works, then submit your code for class Person. We will test it by compiling your code and letting Java link it wity our code for the other classes.

You are free to fix any bugs within class Person that do not require any changes to code in other classes.

Note that you will be completely responsible for issues of style, and that your code will be checked both by javac and by javadoc so make sure there are no errors flagged by either one of them. Quality of Javadoc comments is definitely relevant here!

Submit your code for class Person in the usual way.

A student asked: Do you want us to submit a shell archive or just a single source file holding class Person?

Just submit a single source file, Do not add any of the mechanisms for a shell archive. Do not submit more than one class.

I will distribute the solution as a shell archive so you can see all the classes we use to test your code, but you should only submit one source file.

A student asked: Do we have to use your code or can we break our code into multiple classes?

We will grade your work by compiling your submitted file combined with our files for all the other classes. If your code is compatible with our code, it will work. We really don't care if you use my code for so long a your code works in the context of our code for all the other classes.

That said, the easy path to a solution is just to break the distributed solution to MP8 into separate source files and submit the resulting file. If you really want to submit your file, you'll have to break up my solution so you can test to see how your file works in the context of my solution to the rest of the problem. I will not state that this is impossible, but it is definitely more work!