ducaale
Posts: 4
Nickname: guure03
Registered: Sep, 2002
|
|
Re: new student
|
Posted: Sep 20, 2002 6:31 AM
|
|
here is my question: Write a class called Circle which has two constructors. One takes three doubles in its constructor corresponding to the X and Y coordinates and the radius. The other default constructor supplies default values for the coordinates and radius. Please round computer results to 2 decimal places when displaying results. The class must include these methods: public double circumference() ? returning the circumference public double area() ? returning the area 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) public void printAttributes() ? prints the coordinates, the radius, the circumference and the area. public boolean isInside(int x, int y) ? tests whether or not a point falls inside the circle boundingBox(); ? prints the coordinates for the box that contains the circle move(x, y) ? moves the origin by a specified amount .
here is my work: I need to double check what I did is Ok since3 I am new student for java.
public class Circlex { public double x, y, r; public double MAX; public double circumference (double x, double y, double r) { this.x= x; this.y= y; this.r= r; return this.r *3.14 * this.r; }
public double area() { return 3.14*r*r; } public void setRadius (double r) { double MAXR; MAXR = 100.0 ; if ( this. r > MAXR ) this. r= MAXR; } public void printAttributes() { System.out.println(" r+ circumference + area"); } // is (x,y) inside the circle? public boolean isInside( int x, int y) { double distance; distance = Math.sqrt(x * x + y * y); if (distance < r) return true; else return false; } void boundBox() { System.out.println(" Circle"); } void move ( double x, double y) { this.x = x; this.y = y; } public static void main(String[] args) { } }
Plase let me know.
Thanks
|
|