Java helpz!

Status
Not open for further replies.

DarkMortar

In Runtime
Messages
339
Hi, I need help with this excersise for java. I don't know how to do this very well but it says this, and it should be pretty easy to do, but I need to see how it's done to understand it, thanx and plz help.

Implement a class Circle that has methods getArea() and getPermeter(). In the constructor, supply the radius of the circle.

I have a test on this tommorow! And I need to know how to do similar programs, I sorta get it, but it's still not right. Programming is obviously something I am not good at.
 
This isn't too hard to do. Go and read the section on declaring constructors.

Code:
public class Circle{

      private double radius, area, perim;
      private double pi = 3.14159;

      public Circle(double rad){
           radius = rad;
           area = pi*radius*radius;
           perim = 2*pi*radius;
      }

      public double getArea(){
            return area;
      }

      public double getPerimeter(){
             return perim;
      }
}

::EDIT::
Whoops, I just noitced this was posted on the 27th. I hope you did ok on your test!
 
Status
Not open for further replies.
Back
Top Bottom