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

Could you program it and commenteach line for me...?? thank you in advance.... C

ID: 3611379 • Letter: C

Question

Could you program it and commenteach line for me...?? thank you in advance.... Class: Design a circle class that has the followingfields: - radius : a double - PI : a double initialized with the value 3.14159 the class should have the following methods: - constructor : accept the radius of the circle - setradius : a mutator method for the radiusfield - GetRadius : an accessor method for the radiusfield - Get Area : return the area of the circle : area = PI *radius - GetDiameter: return the diameter of the circle = 2 *radius - GetCircumfrence : return the circumference of thecircle = 2 * PI * radius Menu -------------------------------------------------                         circle 1, Set radius 2, Get the radius 3, Compute the area of the circle 4, Compute the diameter 5, compute the circumference 6, exit -------------------------------------------- Create a circle object and test each menu option. Don't allowthe user to perform 3 - 5 option until option 1 is not done. when using option 1, ask the userinteractively the value of the radius Option 6. exit the program with a statement " bye" Could you program it and commenteach line for me...?? thank you in advance.... Class: Design a circle class that has the followingfields: - radius : a double - PI : a double initialized with the value 3.14159 the class should have the following methods: - constructor : accept the radius of the circle - setradius : a mutator method for the radiusfield - GetRadius : an accessor method for the radiusfield - Get Area : return the area of the circle : area = PI *radius - GetDiameter: return the diameter of the circle = 2 *radius - GetCircumfrence : return the circumference of thecircle = 2 * PI * radius Menu -------------------------------------------------                         circle 1, Set radius 2, Get the radius 3, Compute the area of the circle 4, Compute the diameter 5, compute the circumference 6, exit -------------------------------------------- Create a circle object and test each menu option. Don't allowthe user to perform 3 - 5 option until option 1 is not done. when using option 1, ask the userinteractively the value of the radius Option 6. exit the program with a statement " bye"

Explanation / Answer

/* copy the below code to "Circle.java" to compile : "javac Circle.java" to run "java Circle" */ import java.io.*; import java.util.*; import java.lang.*; public class Circle{ public double radius=0.0; //initialization of variable radius public static double pi = 3.14159; //variable pi is initialisedwith 3.14159 /* Constructer of Circle class which takes an argument forradius and initializes radius of the class */ public Circle( double r)    {    this.radius= r; //the radius of the currentcircle is set to r } public void setRadius( double r) {    this.radius =r; //sets the radius to r } public double getRadius() {    return this.radius; //this function returns theradius of the circle } public double getArea() {    double area = (pi * radius * radius);//calcualtes the area of the circle    return area; //returns the area } public double getDiameter() {    double diameter = (2 * radius); //calcualtes thediameter of the circle    return diameter; //returns the diameter } public double getCircumference() {    double circumference = (2 * pi * radius);//calcualtes the area of the circle    return circumference; //returns thecircumference of the circle } public static void main(String[] args){ int radius_Set=0; /*it stores the value whether radius of thecircle is set...if radius_Set is 1 then only we will allow options3,4,5 to be called */ int choice=0; //stores the choice of the user double radius =0.0; Circle c=null; //initializes a new circle do {    System.out.println("Menu " +"------------------------------------------------- "+"                       circle " +                     "1, Set radius "+ "2, Get the radius " + "3, Compute the area of the circle "+                     "4, Compute thediameter " + "5, compute the circumference " + "6, exit " +                    "--------------------------------------------");    try    {        choice = Integer.parseInt(new BufferedReader(newInputStreamReader(System.in)).readLine());/*reads the choice fromthe system.*/    }    catch (Exception e)    {        e.printStackTrace();    }       if(choice ==1)    {        System.out.print("Enter theRadius: ");        try        {            radius =Double.parseDouble (new BufferedReader(newInputStreamReader(System.in)).readLine()); /*reads the radius fromsystem */        }        catch (Exception e)        {            e.printStackTrace();        }        System.out.println();        System.out.println();        c = new Circle(radius); /*calls teh constructer of the circle with the radius entered by theuser */        radius_Set =1; /* theradius_Set values is 1 now...it allows options 3-5 to be called*/           }       if(choice ==2)    {        System.out.println("Theradius of the circle id: " +(c.getRadius()) );    }       if(choice ==3)    {        if(radius_Set ==1)        {            System.out.println("The area of the circle is: "+(c.getArea()) ); /* now radius is set and we print the area */        }        else            System.out.println("You have not entered the radius...tryagain");               }              if(choice ==4)    {        if(radius_Set ==1)        {            System.out.println("The diameter of the circle is: "+(c.getDiameter()) ); /* now radius is set and we print thediameter */        }        else            System.out.println("You have not entered the radius...tryagain");               }       if(choice ==5)    {        if(radius_Set ==1)        {            System.out.println("The circumference of the circle is: "+(c.getCircumference()) ); /* now radius is set and we print thecircumference */        }        else            System.out.println("You have not entered the radius...tryagain");               }    if(choice ==6)    {        System.out.println("Bye");    }                               } while(choice !=6);                }//end of main }//end of CIrcle class