Question: Rewrite the code in Circle.java and Main.java so that the Circle has a radius instance variable and 5 . 7 only needs to be used

Rewrite the code in Circle.java and Main.java so that the Circle has a radius instance variable and 5.7 only needs to be used once in the entire program to set the value of the radius.
Delete the unnecessary local variables and parameters once the instance variable is set up.
You may add a constructor to Circle.java or a setter method or both.
Add @Override before the toString method and make sure that the program still compiles.
class Main
{
public static void main(String[] args)
{
Circle disk = new Circle();
System.out.println("The "+
disk.toString(5.7)+" has a circumference of "+
disk.getCircumference(5.7)+
" and an area of "+ disk.getArea(5.7));
}
}
import java.lang.Math;
class Circle
{
public double getCircumference(double radius)
{
return 2*Math.PI*radius;
}
public double getArea(double radius)
{
return Math.PI*radius*radius;
}
public String toString(double radius)
{
return "circle with radius "+ radius;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!