Assignment 8, due Mar 25Solutions
Part of
the homework for CS:2820, Spring 2016
|
a) What Java library class or package supports the the exponentiation operation this requires? (0.2 points)
Class Math
b) Is it a class or a package? (0.2 points)
It is a class.
c) Do you have to import this class or package prior to using its members, or is the import implicit? (0.2 points)
It is implicit (class Math is part of the java.lang package).
d) Is there an alternative class or package that can do the same thing? (0.2 points)
Class StrictMath does all the same things.
(Why the difference? Math may be faster, while StrictMath guarantees exactly the same results no matter what machine you operate on. Given that real functions such as exponentiation and the trig functions are computed by approximation algorithms, these may differ slightly.)
e) Give the Java code for corresponding to the assignment statement in the machine problem assignment. You are free to use stupid variable names like t1 where the original code said t1. (Later, in your solution to the machine problem, you might want to re-think some of these names.) (0.2 points)
v2 = (v1 * (float)Math.exp( t1 - t2 )) + s;
Note that the Math.exp function is double precision, while we are (perhaps foolishly) using single precision floating point. Therefore, we need to explicitly discard precision with the (float) cast. The widening of the argument to Math.exp() does not need casting because Java widens without complaining.
a) Which of the actions listed above must involve scheduling new events and cannot be done by simple method calls. (0.5 points)
b) Which of the above do not even necessarily involve different methods but could be folded together into the same method of the same object. (0.5 points)
The rules used to solve the above: If an event causes another at a later time, event scheduling must be involved. If one event causes another at the same time, and the code for the two are naturally embedded in the same class and operate on the same object, then they can be combined into one method.
a) Which bullet points from problem 2 would you need to change to account for the existence of secodary synapses? Give the necessary change(s). (0.5 points)
b) What bullet point(s) would you need to add to account for the existence of secondary synapses? (0.5 points)