Ask Question
26 October, 01:25

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));

}

}

+5
Answers (1)
  1. 26 October, 05:20
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers