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

Write an object oriented program which can calculate the area and circumference

ID: 639052 • Letter: W

Question

Write an object oriented program which can calculate the area and circumference of a circle with a given radius value.

Description: Your program will have two classes.

Class 1: Circle Class
This class has a field named radius and 5 methods: (1) a constructor that accepts the radius of the circle as an argument, (2) a no-argument constructor that sets the radius field to 50.0 (as a default), (3) setRadius method that sets the value of radius, (4) area method that calculates and returns the area of the circle corresponding to the radius value, and (5) circumference method that calculates and returns the circumference of the circle.

Class 2: CircleDemo Class
This class has the main method which creates two circle objects:
Soccer Field with radius 100.
Cricket Field with radius 150.
Play Ground with default radius of a circle.
The main function prints the area and circumference of Soccer Field, Cricket Field, and Play Ground.

Explanation / Answer

class Circle

{

    float radius;

public Circle( floar r)

   {

       radious=r;

   }

public Circle()

{

      radious=50;

}

public void SetRadious(float r)

{

    radious=r;

}

public float AreaCircle()

{

    return 3.14*radious*radious;

}

public float CircumferenceCircle()

{

    return 2*3.14*radious;

}

}

Class CircleDemo

{

   public static void main(String args[])

{

      Circle soccer=new Cicle(100);

     Circle cricket=new Cicle(150);

     Circle playGround=new Cicle();

     float area=soccer.AreaCircle();

      System.out.println("Area"+area);

    float circum=soccer.circumferenceCircle();

    System.out.println("Circumference"+circum);

float area=cricket.AreaCircle();

float circum=cricket.circumferenceCircle();

      System.out.println("Area"+area);

     System.out.println("Circumference"+circum);

float area=playGround.AreaCircle();

float circum=playGround.circumferenceCircle();

      System.out.println("Area"+area);

        System.out.println("Circumference"+circum);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote