Ask Question
12 May, 16:31

The calcCircleCircumf () method invoked within in the CircleStatsTester class is overloaded. Write the overloaded methods in the incomplete public CircleStats class.

public class CircleStats

{

public CircleStats ()

{

}

// ... code goes here - use the Math constant for pi rather than 3.14

}

public class CircleStatsTester

{

public static void main (String[] args)

{

int diameter = 5;

double radius = 2.5;

CircleStats cStats = new CircleStats ();

System. out. println ("The circumference = " + cStats. calcCircleCircumf (diameter));

System. out. println ("The circumference = " + cStats. calcCircleCircumf (radius));

}

}

+1
Answers (1)
  1. 12 May, 20:02
    0
    The program to this question as follows:

    Program:

    class CircleStats / /defining class

    {

    CircleStats () / /creating default constructor

    {

    }

    float calcCircleCircumf (float radius) / /defining method

    {

    return (float) (2 * Math. PI * radius); / /return value

    }

    double calcCircleCircumf (double diameter) / /overload the method

    {

    return (2 * Math. PI * (diameter/2)); / /return value

    }

    }

    public class CircleStatsTester / /defining class

    {

    public static void main (String ar[]) / /defining main method

    {

    int diameter = 5; / /defining integer variable

    double radius = 2.5; //defining float variable

    CircleStats cStats = new CircleStats (); / /creating CircleStats class object

    System. out. println ("The circumference = " + cStats. calcCircleCircumf (diameter)); / /print value

    System. out. println ("The circumference = " + cStats. calcCircleCircumf (radius)); / /print value

    }

    }

    Output:

    The circumference = 31.4

    The circumference = 7.853981633974483

    Explanation:

    In the above java program code, two-class is declared that are "CircleStats and CircleStatsTester". In the class "CircleStats" a default constructor is created then method overloading is performed in which two method is defined that have the same name but different parameters.

    In the first-time method declaration, it contains a float variable "radius" in its parameter to calculate and return its value. In the second time method declaration, it contains a double variable "diameter" in its parameter, calculates and returns its value.

    Then another class CircleStatsTester is defined inside this class the main method is defined. In the main method, an integer and double type variable is defined that contains a value that is "diameter = 5 and radius = 2.5". In this method, an above class CircleStats object is created and call this class functions.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “The calcCircleCircumf () method invoked within in the CircleStatsTester class is overloaded. Write the overloaded methods in the incomplete ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers