0

So I'm still new to programming and I don't know if this is all correct or not, but I'm trying to find the area circumference of a circle with a given radius.

So far I have this:

public class Circle  {

   private double radius;

   public Circle(double r) {

   }

   public double getRadius()  {
      return radius;
   }

   public void setRadius(double r)  {
   }

   public double diameter()  {
      double diameter = radius * radius;
      return diameter;
   }

   public double area()   {
      double area = Math.PI * (radius * radius);
      return area;
   }

   public double circumference()   {
      double circumference = 2 * Math.PI * radius;
      return circumference;
   }
}

I also have this other part too...

public class CircleTest {
   private static void circleTest (int r) {
      Circle circleTest = new Circle(-2);
      System.out.printf("Parameter: %d%n", r);
      System.out.printf("Radius: %.1f %n", circleTest.getRadius());
      System.out.printf("Diameter: %.1f %n", circleTest.diameter());
      System.out.printf("Area: %.1f %n", circleTest.area());
      System.out.printf("Circumference: %.1f %n", circleTest.circumference());
   }

   public static void main(String[] args) {

   }
}

I don't know if this is right or not, but it compiles just fine but it doesn't print anything out when I run it. What am I doing wrong???

james13
  • 45
  • 1
  • 1
  • 7

2 Answers2

0

the code has few mistakes . it has to be like this

public class Circle  {

   private double radius;

   public Circle(double r) {
    radius = r;

   }

   public double getRadius()  {
      return radius;
   }

   public void setRadius(double r)  {
   }

   public double diameter()  {
      double diameter = radius * radius;
      return diameter;
   }

   public double area()   {
      double area = Math.PI * (radius * radius);
      return area;
   }

   public double circumference()   {
      double circumference = 2 * Math.PI * radius;
      return circumference;
   }
}  

main class has to be like this

public class CircleTest {
      public static void main(String[] args) {
         Circle circleTest = new Circle(-2);
              System.out.printf("Parameter: %d%n", r);
              System.out.printf("Radius: %.1f %n", circleTest.getRadius());
               System.out.printf("Diameter: %.1f %n", circleTest.diameter());
              System.out.printf("Area: %.1f %n", circleTest.area());
              System.out.printf("Circumference: %.1f %n", circleTest.circumference());
           }
        }

mistakes you have made 1) your code has to be in main method .2) the constructor parameter has to be set to the class variable.

SabaRish
  • 105
  • 11
-1

In the Java language, when you execute a class with the Java interpreter, the runtime system starts by calling the class's main() method.

The Java Main Method

You should put some code in this block

   public static void main(String[] args) {

   }
bumbumpaw
  • 2,522
  • 1
  • 24
  • 54