On this page:
1 Instructions
Google Map Tiles
1 Introduction
2 What to do
Hints
Criteria for grading
How to submit
7.7

Assignment 2: Designing methods for data

Goals: Learn to design methods for a class, think of exceptional conditions and test them.

1 Instructions

This homework should be done individually.

Please adhere to names of classes and signatures of methods.

Google Map Tiles
1 Introduction

If you have used Google maps (or any other map application) you have seen how it draws the map using rectangular tiles. As you zoom or pan the map, it loads tiles interactively. It does so smartly so that it is not using the data connection more than it needs to.

In order to do this, it always maintains the current part of the map you are looking at as a rectangle. This rectangle has only horizontal and vertical sides. The rectangle is represented by its lower-left corner (x,y), its width and its height. All of them are assumed to be integral data, for simplicity. When you move the map in any way it determines whether it must load additional map tiles, and if so, which ones. For example:

Although implementing any part of Google Maps seems daunting, all these operations can be implemented on rectangles. The above list corresponds to checking if two rectangles overlap, determine the intersection of two rectangles and the union of two rectangles. The figure below illustrates these operations. Note that the union of two rectangles is always a rectangle. Also the intersection of two rectangles is always a rectangle, if it exists.

2 What to do

For this assignment, you must write a class Rectangle and a tester RectangleTest. The Rectangle class should have only the following public methods (you can add other non-public methods):

There exists a class called Rectangle in Java already. You are not allowed to use this class in any way! Make sure that you are not accidentally importing it!

A few suggestions about tests:
  • You need more than one tests for overlap, because there can be several kinds of overlap. Think about it!

  • Write as many tests as you can think of. But you do not need to conflate many tests into one method: for example, you can write several different methods to test just overlap provided you isolate the objective of each test.

Hints

None of the methods for the Rectangle class need to be large and complicated, if you think about them carefully. Drawing out several cases and reasoning out these methods on paper may help!

Criteria for grading

You will be graded on:
  1. The correctness of your methods.

  2. Whether your code looks well-structured and clean (i.e. not unnecessarily complicating things, or using unwieldy logic).

  3. How well you have tested your methods.

  4. Whether you have written enough comments for your classes and methods, and whether they are in proper Javadoc style.

  5. Whether you have used access modifiers correctly: public and private.

  6. Whether your code is formatted correctly (according to the style grader).

How to submit
  1. Create a zip file that contains directly your src and test folders. When you unzip the file, you should see only these two folders.

  2. Log on to the Bottlenose submission server.

  3. Navigate to Assignment 2 and submit the zip file.

  4. Wait for a few minutes for feedback to appear, and take action if needed.