Testing the Point class
TestPoint class
Note: the following code should be in a file named
TestPoint.java
.
/*******************************************************************************
Program: TestPoint
Author: Rebecca Hasti, hasti@cs.wisc.edu
copyright 2000, all rights reserved
Course: CS 302
Compiler: Metrowerks CodeWarrior (JDK 1.2)
Platform: Windows NT 4.0 / 95 / 2000
*******************************************************************************/
/**
* This program tests the Point class.
*
* Bugs: none known
**/
class TestPoint {
public static void main(String args[]) {
// declare two Point variables
Point point1, point2;
// create two Point objects
point1 = new Point(2.5, 10.8);
point2 = new Point();
System.out.println("**** Test constructors ****");
point1.print(); // print out point1
point2.print(); // print out point2
// test setX and setY
System.out.println("**** Test mutator methods ****");
point1.setX(99);
point1.setY(88);
point1.print();
// test getX and getY
System.out.println("**** Test accessor methods ****");
System.out.println("point1.getX() = " + point1.getX());
System.out.println("point1.getY() = " + point1.getY());
// illustrate how assignment assignment works
double xPoint1, yPoint1;
Point point3;
point3 = point1; // assign point1 to point3
xPoint1 = point1.getX(); // assign point1's x and y coordinates
yPoint1 = point1.getY(); // to xPoint1 and yPoint1, respectively
point2.setX(xPoint1); // set point2's x and y coordinates
point2.setY(yPoint1);
// print out all the points
System.out.println("**** Illustrate assignment ****");
System.out.print("point1 = ");
point1.print();
System.out.print("point2 = ");
point2.print();
System.out.print("point3 = ");
point3.print();
point3.setX(33); // set point3's x coordinate to 33
// print out all the points
System.out.println("-------------------------------");
System.out.print("point1 = ");
point1.print();
System.out.print("point2 = ");
point2.print();
System.out.print("point3 = ");
point3.print();
} // end method main
} // end class TestPoint
Output from TestPoint program
Note: the output will appear in a MSDOS window with
a black background, white letters, and the title of the window
set to java
. This is the console window.
**** Test constructors ****
(2.5, 10.8)
(0.0, 0.0)
**** Test accessor methods ****
(99.0, 88.0)
**** Test mutator methods ****
point1.getX() = 99.0
point1.getY() = 88.0
**** Illustrate assignment ****
point1 = (99.0, 88.0)
point2 = (99.0, 88.0)
point3 = (99.0, 88.0)
-------------------------------
point1 = (33.0, 88.0)
point2 = (99.0, 88.0)
point3 = (33.0, 88.0)