Hello all,
I have to create the following program, and I am totally confused.Your help is greatly appreciated. Thanks.
Program:
Write a class called Circle which has two constructors. The first constructor (default constructor) does not take any parameter and supplies default values for the coordinates and the radius. The second constructor takes three doubles as parameters corresponding to the X and Y coordinates and the radius. The class must include these methods:
public double circumference() – returns the circumference of the circle.
public double area() – returns the area of the circle.
public void setRadius(double r) – is called in the constructor and checks the radius against a maximum. If the radius is greater than the maximum, setRadius resets it to the maximum (using the ternary conditional operator). You may set your own maximum value. ---I dont know how to do so.
public void printAttributes() – prints the coordinates, the radius, the circumference, and the area.
public boolean isInside(double x, double y) – return true if a point represented in the parameters falls inside the circle, false otherwise.----I dont get the question
public void move(int x, int y) – moves the origin by a specified amount. --- I dont get the question
My work so far:
Code:public class Circle { public double radius; public double xCoord; public double yCoord; public double maxR=100.00; public static void main(String[] args) { Circle cir= new Circle(); cir.printAttributes(); } public Circle(){ radius=0; xCoord=0; yCoord=0; } public Circle(double x,double y,double r){ radius=r; xCoord=x; yCoord=y; } //It is called in the constructor and checks the radius against a maximum. public void setRadius(double r){ radius=r; //r=radius>maxR ?maxR:radius; } //Returns the circumference of the circle. public double circumference(){ return Math.PI*2*radius; } //Returns the area of the circle. public double area(){ return (radius*radius)*Math.PI; } //Prints the coordinates, the radius, the circumference, and the area. public void printAttributes(){ System.out.println("Area is:"+area()+" Circumference is: "+circumference()+" Radius is: "+radius); } //Returns true if a point represented in the parameters falls inside the circle, false otherwise. public boolean isInside(double x, double y) { double distance; distance= Math.sqrt(x*x+y*y); if(distance<radius) return true; else return false; } //Moves the origin by a specified amount. public void move(int x, int y) { x=x; y=y; } }