Point - Circle - Cylinder

 Now we enhance the Point and Circle classes and develop a package for them so that we can import methods and variable instances.  We develop the Point class then extend it into the Circle.  Then we extend the Circle class to develop the Cylinder class.  This also serves to illustrate some differences between packaging and using some features of a class, of ten called composition and using inheritance to extend a class. First we will redevelop the Point class, then we will develop the Circle class and then we will test them. Now the code for Point.java should be copied into a new directory. // Point.java // Setting a point package edu.quinnipiac.javaProgs.geometry; public class Point { protected int x, y; // No argument constructor public Point() { // implicit call to superclass constructor occurs here setPoint(0,0); } // Constructor public Point(int a, int b) { // implicit call to superclass constructor occurs here setPoint(a,b); } // Set the x and y coordinates of Point public void setPoint(int a, int b) { x = a; y = b; } // get x coordinate public int getX() { return x; } // get y coordinate public int getY() { return y; } // convert the point into a String representation public String toString() { return "[" + x + ", " + y + "]"; } }Now we want to test this class we've developed after making sure we use the javac -d c:\jdk1.2.1\jre\classes Point.javato create the package class.Now you want to test this with TestPoint.java.// TestPoint.java // Application to test class Point import javax.swing.JOptionPane; import edu.quinnipiac.javaProgs.geometry.Point; public class TestPoint { static void main( String args[ ]) { Point p = new Point(72,115); String output; output = "X coordinate is " + p.getX() + "\nY coordinate is " + p.getY(); p.setPoint(10,10); // Use implicit call to p.toString() output = output + "\n\nThe new location of p is " + p; JOptionPane.showMessageDialog(null, output, "Demonstrating Class Point", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }