Computer Science 252
Problem Solving with Java

Spring 2015, The College of Saint Rose

Lecture 4: Dragging; Working with Colors
Date: Thursday, January 22, 2015


Agenda

Lecture 4 Assignment

Due at the start of class, Tuesday, January 27.

Please submit answers to these questions in Submission Box under "LA4" or in hard copy by the start of our next class. We will discuss these questions at the start of class, so no late submissions are accepted. Please be sure that your name is clearly indicated in all submissions.

  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)

Terminology

Examples