Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.
Dell Dimension 4600
Intel Pentium 4 2.6Ghz w/ HT and 800Mhz fbs.
1.5GB DUAL CHANNEL DDR SDRAM RAM 400mhz
ATI Radeon 9800 PRO 128MB DDR
120GB ATA 7200HD
Sound Blaster Live! 5.1
4.1 Al

Ok I made the test file correctly.
public class CircleTest
{
public static void main(String[] args)
{
Circle myCircle = new Circle(10);
System.out.println(myCircle.getArea());
}
}however my other one isnt lol
public class Circle
{
public Circle(10)
{
radii = 10;
}
public void formula(double formula)
{
formula = 3.14 * radii * radii;
}
public double getArea()
{
return getArea();}
}Dell Dimension 4600
Intel Pentium 4 2.6Ghz w/ HT and 800Mhz fbs.
1.5GB DUAL CHANNEL DDR SDRAM RAM 400mhz
ATI Radeon 9800 PRO 128MB DDR
120GB ATA 7200HD
Sound Blaster Live! 5.1
4.1 Al

to make the Circle class
assuming radius is a property that the class contains:public class Circle {
//Initialize the properties ie radius
int radius;//Constructors
Circle(int radius) {
this.radius = radius;
}public double getArea() {
return radius * radius * 3.14;
}//Perimeter aka Circumference
public double getPerimeter() {
//With Circumference bein 2*pi*r
return 2 * 3.14 * radius;
}
}
this should be correct although im not 100 percent sure on the problem specs.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |