Assignment 4Due Feb 17 on line
Part of
the homework for CS:2820, Spring 2021
|
a) So we can look up roles by name.
b) So we do not forget any roles after their populations are created.
c) So we can create the people for each role after we know all roles.
— correct
d) So we can find all the people associated with each role.
e) all of the above.
It is not necessary to look up roles by name for MP2, although MP3 will need this, so a) is a poor fit. Roles will not be forgotten if each person has a link to the associated role, so b) is wrong. Nothing in MP2, or even in MP3 requires searching for people by role, so d) is wrong. The math for determining how many people to create for each role requires knowing the sum of the numbers for all roles, so it is impossible to create the population for any role before all are known. This forces listing all the roles, making c) correct.
Note that one issue was not listed above that also justifies keeping a list of all roles: Such a list is needed to detect redefinition of a role, or put another way, to detect two roles with the same name.
a) Semicolons make more sense as terminators than periods.
b) Class Scanner offers no help finding line boundaries.
c) Class Scanner mostly treats line boundaries like space or tab.
— correct
d) The choice was entirely arbitrary.
e) Java offers no tools for working input one line at a time.
Only programmers seem to think semicolons are a sensible way to terminate something, so a) is wrong. Class scanner does offer findInLine, hasNextLine and nextLine methods, so b) is false. Option c) is certainly true — most of the methods of class Scanner treat newlines like space and tab by default. Option d) is wrong, because the decision was made only after looking at the tools provided by class Scanner and its competitors. Finally, option e) is wrong, among other things, because of the reasons offered to show that b) is wrong.
a) The epidemic simulator is too big for the Waterfall model.
b) The waterfall model only applies to government projects.
c) Waterfall specifications take the form of screen shots.
d) The waterfall model does not work with object-oriented code.
e) The waterfall model needs a complete specification to start with.
— correct
The waterfall model works with any size problem (the GPS satellite system discussed in class is a huge example problem), so a) is wrong. Nothing about the waterfall model requires that it apply to government, so b) is wrong. Nothing about the waterfall model require the use of screen shots (and the GPS example never mentioned this), so c) is wrong. Nothing about the waterfall model cares about the programming language being used, so d) is wrong. This leaves e). The most elementary discussion of the waterfall model always begins with a complete specificaiton before any work on coding begins.
a) void newX()
b) X newX()
c) static void newX()
d) static X newX()
— correct
e) all of the above could be made to work
This question is purely about Java, and drove many students to look at the textbook. If we replace a call to a complex constructor new X() with X.newX(), then the newX method must return an object of class X, making a) and c) wrong. If the method call is replacing a constructor call, it must not need some object x of class X to be called, as in x.newX(), so b) is wrong.
a) m must not be static.
— correct (see note)
b) class c must be public.
c) method m must not be defined in a superclass of c.
d) o must not be a static variable.
e) x must not be a private variable.
This question is also purely about Java, and drove many students to look at the textbook. First, a) is trivially true (see note). If class c is not public, the call in question would still be legal within the body of class c or within other classes defined in the same source file, so b) is wrong. If class c inherits m from a superclass, that makes no difference so c) is wrong. So long as o is visible in the context where o.m(x) is used, the fact that o is static, an instance variable, a local variable or a parameter is irrelevant, so d) is wrong. Similarly, so long as x is visible where used, the fact that it is public or private is irrelevant, so e) is wrong.
Note: As it turns out, Java does allow o.m(x) when m is a static method. I did not know this little obscurity of Java until after this was graded, and even knowing it, it's not easy to figure out why it's legal, since calling o.m(x) for a static method cannot have an effect that depends on or makes any changes to o, so such method calls are going to be very rare in practice.
So how do you deal with questions like this? The categories true and false are very binary, but English has gradiations of meaning. All 5 options have the word "must" in them. If you shift "must" to "should," replacing absolute prohibition with recommendation, a) becomes true while the others remain nonsense. There are perfectly reasonable reasons for violating the b) through e) in recommended form, while a) in recommended form is a quite reasonable recommendation.