Chapter 1: Introduction to Programming

  1. A type is the set of values that a variable can have, and the operations that can be performed with those values
  2. one is declared as int; thus, its type must be int
  3. 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
  4. The cast is required because you cannot store a double value in an int variable.
  5. 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

  1. Only the public attributes and methods of a utility appear in the API.
  2. int
  3. No, there is no precondition section in the API for the method.
  4. An exception will be thrown (as per the postcondition).
  5. 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

  1. Integer
    float
    long
    int
    Integer
  2. parseInt(String s, int radix)
    toString(int i)
    toString()
    valueOf(String s)
    valueOf(int i)
  3. There are zero mutator methods.
  4. Yes, a method can change the state of an object if it is given a reference to the object as an argument.
  5. 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

  1. default
  2. copy
  3. ==
  4. equals
  5. 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.