Results 1 to 4 of 4

Thread: class Circle

  1. #1
    JojoDiaz is offline Member
    Join Date
    Sep 2011
    Posts
    29
    Rep Power
    0

    Post class Circle

    Hey everyone. I'm writing a class Circle to get this to run correctly.

    Here's what i have

    import java.io.*;
    import java.util.Scanner;
    /////////////////////////////////////////////////////////////////////////
    class Hw06
    {
    //-----------------------------------------------------------------------
    public static void main ( String [] args ) throws Exception
    {
    Circle c1 = new Circle(1.0);
    report(c1);
    Circle c2 = new Circle(0.56418958);
    report(c2);
    c2.setRadius(0.1591549431);
    report(c2);
    }
    //-----------------------------------------------------------------------
    public static void report ( Circle c )
    {
    System.out.println();
    System.out.printf("radius %6.4f\n",c.getRadius());
    System.out.printf("area %6.4f\n",c.area());
    System.out.printf("perimeter %6.4f\n",c.perimeter());
    }
    //-----------------------------------------------------------------------
    } // end class Hw06
    /////////////////////////////////////////////////////////////////////////
    class Circle
    {

    } // end class Circle
    /////////////////////////////////////////////////////////////////////////

    i need to write methods area and perimeter

    what it does it get the radius area and perimeter of a circle

    If anyone can explain to me what i need to do or help me with how to do it that would be great!
    I thank you in advance.

  2. #2
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default Re: class Circle

    You must have a constructor that has a parameter of double/float
    Java Code:
    Circle c1 = new Circle(1.0);
    You should have a variable in Circle and a method that will set value of that variable (the parameter) that you passed
    Java Code:
    c2.setRadius(0.1591549431);
    You should have a method in Circle named it getRadius(), area(), perimeter() which returns a value
    Java Code:
    System.out.printf("radius %6.4f\n",c.getRadius());
    System.out.printf("area %6.4f\n",c.area());
    System.out.printf("perimeter %6.4f\n",c.perimeter());

  3. #3
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default Re: class Circle

    For next time would you be able to put your code in "code" brackets. It's just easier to read.

    Java Code:
    public void setRadius(double radius){
    		this.radius = radius;
    	}
    public double getRadius(){
    		return radius;
    	}
    public double getArea(){
    		double area = 3.14 * radius * radius;
    return area;
    //.....
    	}
    You will need to make a methods similar to this.
    Last edited by kraigballa; 10-12-2011 at 06:39 AM.

  4. #4
    JojoDiaz is offline Member
    Join Date
    Sep 2011
    Posts
    29
    Rep Power
    0

    Default Re: class Circle

    Thank you so much, finally got it working!

Similar Threads

  1. how to unpaint my circle
    By vettera in forum AWT / Swing
    Replies: 2
    Last Post: 09-12-2011, 05:43 AM
  2. Simple help with a circle.
    By Nap in forum New To Java
    Replies: 19
    Last Post: 08-08-2011, 04:00 PM
  3. Why is there no circle?
    By JohnPringle83 in forum New To Java
    Replies: 3
    Last Post: 05-23-2011, 08:07 AM
  4. is this circle okeh ?
    By SHE in forum New To Java
    Replies: 0
    Last Post: 04-14-2011, 05:34 AM
  5. Josephu's Circle
    By Pyrexkidd in forum New To Java
    Replies: 8
    Last Post: 08-01-2010, 08:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •