CISC 3115
Introduction to Modern Programming Techniques
Lab #2
Using Classes and Objects

How to Develop and Submit your Labs

Lab 2.1 — Using a Point Class (PointApp) (Approval)

Overview

In this exercise, you will be working with a class that represents two-dimensional points (i.e., points with x and y coordinates). (Before you get too nervous... there is no math to be done here :).)

This class — named Point has already been written, compiled, tested, and documented. The documentation was produced using a standard Java development tool known as javadoc. javadoc takes one or more Java source files that have been marked-up with appropriately formatted comments, and produces a set of HTML pages known as an API (Application Programmers Interface)i. (The entire Java class library that comes with the Java Development Kit is documented in the same fashion, and is collectively known as the Java API — you can access it by Googling Java API. The API produced for a class includes all public fields (remember a field is a method, variable, or constant of a class) of the class, broken up into sections for constants, variables (rarely present — remember, variables belonging to a class are typically declared private), constructors, and methods. The whole thing is hyperlinked to allow cross-referencing.

Files and Information Provided to You

What You Are to Do

Code an application class (i.e., a class containing a main method), named PointApp that reads point data (i.e., x and y coordinates) from the file points.text. This data is then used to create pairs of Point objects which are then used to flex (i.e., illustrate) the methods of the class.

The format of the points.text file is:

xpoint1 ypoint1  xpoint2 ypoint2
i.e., pairs of x/y coordinates, resulting in data for 2 Point objects per line.

Sample Test Run

For example if the file points.text contains:

0 0   1 1
1 1   1 -1
1 1   -1 1
1 1   -1 -1
0 0   0  0
1 1   1 1
1 1   -2 -2
the program should produce the following output:
p1: (0, 0) (quadrant 0) / p2: (1, 1) (quadrant 1)
p1+p2: (1, 1) (quadrant 1)
The distance between (0, 0) and (1, 1) is 1.4142135623730951

p1: (1, 1) (quadrant 1) / p2: (1, -1) (quadrant 4)
p1+p2: (2, 0) (quadrant 4)
p1 and p2 are reflections across the x-axis
p1 and p2 are equidistant from the origin
The distance between (1, 1) and (1, -1) is 2.0

p1: (1, 1) (quadrant 1) / p2: (-1, 1) (quadrant 2)
p1+p2: (0, 2) (quadrant 0)
p1 and p2 are reflections across the y-axis
p1 and p2 are equidistant from the origin
The distance between (1, 1) and (-1, 1) is 2.0

p1: (1, 1) (quadrant 1) / p2: (-1, -1) (quadrant 3)
p1+p2: (0, 0) (quadrant 0)
p1 and p2 are reflections through the origin
p1 and p2 are equidistant from the origin
The distance between (1, 1) and (-1, -1) is 2.8284271247461903

p1: (0, 0) (quadrant 0) / p2: (0, 0) (quadrant 0)
p1+p2: (0, 0) (quadrant 0)
p1 and p2 are reflections across the x-axis
p1 and p2 are reflections across the y-axis
p1 and p2 are reflections through the origin
p1 and p2 are equidistant from the origin
The distance between (0, 0) and (0, 0) is 0.0

p1: (1, 1) (quadrant 1) / p2: (1, 1) (quadrant 1)
p1+p2: (2, 2) (quadrant 1)
p1 and p2 are equidistant from the origin
The distance between (1, 1) and (1, 1) is 0.0

p1: (1, 1) (quadrant 1) / p2: (-2, -2) (quadrant 3)
p1+p2: (-1, -1) (quadrant 3)
The distance between (1, 1) and (-2, -2) is 4.242640687119285

Some Guidance and Notes

Submitting to Codelab