Computer Science 252
Problem Solving with Java

Fall 2015, The College of Saint Rose

Lecture 5: Dragging; Working with Colors
Date: Tuesday, September 15, 2015


Agenda

Lecture 5 Assignment

Due at the start of class, Tuesday, September 22.

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

  1. (3 points) It is important to be able to differentiate between the cases when two variables refer to the same object, and when they refer to different objects. This question used Objectdraw's Location class to demonstrate this.

    Suppose you have the following instance variable declarations in a program:

      private Location a, b, c;
    

    and later in the program, the following statements are executed:

       a = new Location(100, 100);
       b = new Location(200, 200);
       c = a;
    
       a.translate(25, -25);
       b.translate(10, 10);
       c.translate(15, 15);
    

    What are the x and y coordinates in the Locations referenced by the variables a, b, and c?

  2. (4 points) It is also important to understand the difference between comparing objects using the == operator and the equals method.

    Suppose you have the following instance variable declarations in a program:

      private Location e, f, g;
    

    and later in the program, the following statements are executed:

       d = new Location(100, 100);
       e = new Location(100, 100);
       f = d;
    

    Evaluate each of these expressions:

      d == e
    
      d.equals(e)
    
      d == f
    
      d.equals(f)
    

Examples