Chapter 1: Introduction to Programming
- A type is the set of values that a variable can have,
and the operations that can be performed with those values
- one is declared as int; thus, its type must be int
- f is a double and 49 is an int literal; thus, the 49 will
be promoted to double and the product will be computed as a double
- The cast is required because you cannot store a double
value in an int variable.
- The value of (f * 49) is close to, but not exactly, 1
because floating point calculations are imprecise.
The fact that the variable one has the value zero implies
that (f * 49) must be slightly less than 1 (0.9999999.....)
which when cast to int becomes 0.
Chapter 2: Delegation
- Only the public attributes and methods of a utility appear in
the API.
- int
- No, there is no precondition section in the API for the method.
- An exception will be thrown (as per the postcondition).
- The method implementer is responsible for the error, as
it violates the postcondition (returns the number of days,
or throws an exception).
Chapter 3: APIs
- Integer
float
long
int
Integer
- parseInt(String s, int radix)
toString(int i)
toString()
valueOf(String s)
valueOf(int i)
- There are zero mutator methods.
- Yes, a method can change the state of an object if it
is given a reference to the object as an argument.
- No, a method cannot change the identity of an object
even if it is given a reference to the object as an argument.
Chapter 4: Using Objects
- default
- copy
- ==
- equals
- The identity of an object is some unique distinguishing feature
of the object; the address of the block of memory that the object
resides in is a suitable candidate for its identity because only
one object can occupy a given block of memory at any given time.
The state of an object is the values of the attributes (e.g., the
values of the numerator and denominator for a Fraction object).
Chapter 5: Control
1. Modify the program so that it outputs the values of i and sum
at points A and B in the loop, and run the program.
Chapter 6: Strings
You should be able to figure these out on your own.