I would like some help with this program that I wrote for my class project. I have a class Point, class Circle and a main test program. I'm having difficulty with where to put some if else statements to find the quadrant that the points x,y are located. I wrote a bunch of if else statements to find the quadrant but I can't seem to get the test program to print them in my output box. Where would I place the code for this? class Point? How do I get the test program to recognize it? I'm a little confused but it may be because I'm over-thinking the solution. I'm not asking for anyone to do my homework I just need a little push in the right direction. Any help would be greatly appreciated....
I posted my code below.......
// Example: Point.java
// Definition of class Point
public class Point {
protected int x, y; // coordinates of Point
// No-argument constructor
public Point()
{
// implicit call to superclass constructor occurs here
setPoint( 0, 0 );
}
// constructor
public Point( int xCoordinate, int yCoordinate )
{
// implicit call to superclass constructor occurs here
setPoint( xCoordinate, yCoordinate );
}
// set x and y coordinates of Point
public void setPoint( int xCoordinate, int yCoordinate )
{
x = xCoordinate;
y = yCoordinate;
}
// get x coordinate
public int getX()
{
return x;
}
// get y coordinate
public int getY()
{
return y;
}
// convert into a String representation
public String toString()
{
return "[" + x + ", " + y + "]";
}
} // end class Point
// Example: Circle.java
// Definition of class Circle
public class Circle extends Point { // inherits from Point
protected double radius;
// no-argument constructor
public Circle()
{
// implicit call to superclass constructor (default) occurs here
setRadius( 0 );
}
// constructor
public Circle( double circleRadius, int xCoordinate,
int yCoordinate )
{
// call superclass constructor to set coordinates
super( xCoordinate, yCoordinate );
// set radius
setRadius( circleRadius );
}
// set radius of Circle
public void setRadius( double circleRadius )
{
radius = ( circleRadius >= 0.0 ? circleRadius : 0.0 );
}
// get radius of Circle
public double getRadius()
{
return radius;
}
// calculate area of Circle
public double area()
{
return Math.PI * radius * radius;
}
// convert the Circle to a String (Note that this uses superclass variables, x and y)
public String toString()
{
return "Center = " + "[" + x + ", " + y + "]" +
"; Radius = " + radius;
}
} // end class Circle
// Example: Test2.java
// Application to test class Circle and Point
// Java core packages
import java.text.DecimalFormat;
// Java extension packages
import javax.swing.JOptionPane;
public class Test2 {
// test class Circle
public static void main( String args[] )
{
// create a Circle (hard-coded, one example object)
Circle circle = new Circle( 2.5, 37, 43 );
DecimalFormat precision2 = new DecimalFormat( "0.00" );
// get coordinates and radius of the first object
String output = "X coordinate is " + circle.getX() +
"\nY coordinate is " + circle.getY() +
"\nRadius is " + circle.getRadius();
// set coordinates and radius; change the values
circle.setRadius( 4.25 );
circle.setPoint( 2, 2 );
// get String representation of Circle and calculate area using new values
output +=
"\n\nThe new location and radius of c are\n" + circle +
"\nArea is " + precision2.format( circle.area() );
JOptionPane.showMessageDialog( null, output,
"Demonstrating Class Circle",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
} // end class Test