CS 110: INTRODUCTION TO PROGRAMMING IN Java
Kalamazoo College

DISCUSSION QUESTIONS
on Testing Rectangle Code


The Review/Discussion questions for F1 cover code that constructs a Rectangle object and adds a point to it. (Exercise R2.11) If, after reading the documentation for the add method of the Rectangle class, you are not convinced that you understand the code or its results, you can write a small code snippet to test it.

You may start with the following code to test the results of constructing the rectangle and adding a point to it.

import java.awt.Rectangle

public class RectangleTester
{
    public static void main(String[] args)
    {
        Rectangle box = new Rectangle(5,10,20,30);

        // add the point (0,0) to this Rectangle
        box.add(0,0);

        // Print out information about the modified rectangle
        System.out.println("x: " + box.getX());

        System.out.println("y: " + box.getY());

        // Add more print statements here to print the box's
        // width and height.

    }
}
To use this code, create a new project in BlueJ. Then create a new class in your new project. Copy this code and paste it over the template for the class you just created. Run the code. Add a few more print statements to convince yourself what is happening.