Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For some reason I am getting an error message for using the same name inside the

ID: 3771294 • Letter: F

Question

For some reason I am getting an error message for using the same name inside the class. Can someone tell me how to fix this?

class AreaClass
{
   static final double pi = Math.PI;
  
   //Circle method
   static double Area(double radius)
   {
       return pi*radius*radius;
   }
  
   //rectangles method ??call it an int?
   static double Area (double width, double length)
   {
       return width * length;
   }
  
   //Cylinders method
   static double Area (double radius, double height)
   {
       return pi *radius*radius*height;
   }
  
}

Explanation / Answer

//Rename any one Area method

class AreaClass {

   static final double pi = Math.PI;

   // Circle method

   static double Area(double radius) {

       return pi * radius * radius;

   }

   // rectangles method ??call it an int?

   static double Area(double width, double length) {

       return width * length;

   }

   // A class can't have two methods with same name and same number and type of

   // parameters

   // rename Area() method to something else

   //Here you both Area methods have same name and same number and same type of arguments i.e double,double

   // Cylinders method

   static double CylinderArea(double radius, double height) {

       return pi * radius * radius * height;

   }

}