Computer Science 252
Problem Solving with Java

Spring 2016, The College of Saint Rose

Lecture 4: Dragging; Working with Colors
Date: Thursday, January 28, 2016


Lecture 4 Assignment

Due at the start of class, Tuesday, February 2.

Please submit answers to these questions either as a hard copy (typeset or handwritten are OK) or by email to terescoj AT by the start of class. Please use a clear subject line when submitting by email (e.g., CSC 252 Lecture 4 Assignment , Joe Student). We will discuss these questions at the start of class, so no late submissions are accepted.

  1. (Hand this question in on paper next class.) Print a copy of the code from the CrazyColorfulSpiralLines example and label an example of each of these constructs: (i) a method call, (ii) a mouse event handler method, (iii) a local variable declaration, (iv) a formal parameter, (v) a class name, (vi) a class comment, (vii) a method header, (viii) an object construction, (ix) an actual parameter, (x) an instance variable declaration. (10 points, 1 each)
  2. Summarize in a sentence or two when a variable should be declared as an instance variable and when it should be declared as local to the method in which it is used. (2 points)
  3. Write a program called ElapsedTime that displays, in a Text object on the canvas, the number of seconds between the most recent two mouse clicks.

    Note that System.currentTimeMillis returns the number of milliseconds since some fixed time in the past, as a long value. In case you haven't used them, long values work just like int values but can store a much larger range of values (264 values rather than the 232 that can be stored by ints).

    If you know the return value of System.currentTimeMillis at some time in the past, the number of milliseconds since that time can be computed by the difference between the current return of System.currentTimeMillis and that previous return value.

    Hint: this is a lot like the ClickCounter example, except the number you are to display is not the counter, but the result of the subtraction of the previous click time from the current click time.

    Note: this is a restatement of BDM Exercise 5.8.1, p. 149. (10 points)



(Don't worry, we won't do all of these in one day)