CS 161 Assignment 4
Classes, constructors and more

Due date - Friday, February 24th at 5:00 p.m.

Version

Version 1.0 - Initial release

Overview

In this assignment you will finish the implementation of three classes in a stepwise manner:

Description

This program deals with Points, that are elements of a Cloud (a set of Points). The client code Assign4 will read in a number of Points, put them in a Cloud, and perform testing. You will implement this program in a step-wise fashion: first you will implement Point, and test it using test methods you have designed for Point, then you will implement Cloud, and test it using test methods you have designed for Cloud, then you will implement Assign4, and test it using the test methods you have designed for Assign4.

Point

A Point in a two dimensional plane has double x and double y coordinates. The Point(x,y) constructor must set the values of the provided instance variables x and y. The Point() constructor will create an origin (0.0,0.0) by calling the Point(x,y) constructor using this.

The getx and gety methods will return the value of these instance variables. The setx and sety methods will set the instance variables. The toString method will produce a String (x,y), eg "(0.0,0.0)". The equals method will check for equality of two Points. Because x and y are doubles, Equals compares x and p.x by checking whether the absolute difference of the two is less than a provided epsilon value, and does the same for y and p.y. The euclidDistance method computes the Euclidian distance between this and another point: the square root of the sum of (x - p.x) squared and (y - p.y) squared.

Your testing should be be implemented in the main program and should exercise all the methods of Point - especially the corner cases. When we run the grading program, we will be doing exactly that.

Cloud

When you are happy with Point, move on to Cloud. The instance variables of Cloud are Point[] points, an array that will hold the points of the Cloud, int maxSize, the max Size of the Cloud and hence the size of array points, and int size, the actual number of Points currently in points. Obviously size is less-equal maxSize. The methods isFull and isEmpty check whether the Cloud is full or empty, hasPoint uses the equals method of Point to check whether a given Point occurs in the Cloud, the constructor Cloud initializes the instance variables, addPoint adds a Point to the Cloud and returns true if there is still space, if not it returns false. The toString method uses Arrays.toString and the toString method of Point to create a String from the Cloud. The extremes method returns null if the Cloud is empty, and an array of Points: leftmost, rightmost, top, bottom otherwise. The centerP method creates a center Point (average x and average y of the Cloud). The minDist method returns null if the Cloud is empty, and an array of the two Points in the Cloud that are closest together otherwise. If the Cloud has only one Point, return a size 1 array with that one Point in it.

Your testing should be be implemented in the main program and should exercise all the methods of Cloud - especially the corner cases. When we run the grading program, we will be doing exactly that.

Assign4

Only when you have tested with Point and Cloud, move on to Assign4. The main method reads a filename from the command line (so make sure your Eclipse session is set up correctly), creates a Scanner and calls readPoints with that, and then tests your Cloud and Point classes.

Here all you need to do is implement the readPoints method, that given a Scanner, first reads n the number of points, the creates a Cloud of appropriate maxSize, then reads n points and adds these to the Cloud. Example File You can use the debug flag to have conditional debugging code, which should have no effect (produce no output) when debug is false.

Your testing here should exercise the entire system.

Testing

Start testing Point using your test cases. You should NOT move on to Cloud until you have finished Point and it passes all your test cases. Be SURE your test cases exercise all the methods of Point and that they cover the corner cases. Take the time to put some thought into what those corner cases are.

Once you are satisfied that Point is rock solid, start testing Cloud using your test cases. Again, do NOT move on to Assign4 until you are satisfied Cloud is rock solid. Be SURE your test cases exercise all the methods of Cloud - especially the corner cases. Take the time to put some thought into what those corner cases are. You can be sure that OUR grading test cases will do so.

Testing of Assign4 should encompass the entire system. What does that mean? How should you test the entire system? Again, thought first, then coding.

The debug flag can help you to put debugging print statements in your code. You must be able to turn debugging off by setting debug to false. Make sure you have tested your programs using javac and java on a department Linux machine.

Submitting Your Assignment

If you used the debug flag, make SURE you turn it to false before submitting.

Programming assignments will be submitted using RamCT. You can submit the assignment by selecting Assignments in the Course Menu and selecting the appropriate assignment within the Assignments section. Once you have selected the correct assignment, you should attach all files indicated by the directions of the assignment and submit the assignment for grading.

After you have submitted the assignment, be sure to verify that the assignment was submitted correctly by clicking on the submitted tab under Assignments and verifying that the files that were submitted are correct. Attaching incorrect files is one of the most common problems . it is the responsibility of the student to ensure that the correct files were submitted for the assignment.

Once an assignment has been submitted, you can unsubmit the assignment by locating the assignment under the submitted tab, clicking on the pull-down menu associated with the assignment and selecting the Take back assignment to Inbox. This will allow you to modify the attached files and resubmit the assignment.

BE SURE to submit the modified assignment when you are finished.

    The following files should be checked in as a part of this assignment.
    Do NOT tar or zip these files up, attach each file individually to the assignment.

  1. Point.java
  2. Cloud.java
  3. Assign4.java