Question: Circle.java class Circle { private double radius; private double area; private double diameter; Circle() { } public void setRadius(double r) { } public double getRadius()

Programming Exercise 4-6 C Instructions Ll Create a class named circle with

Circle.java

class Circle { private double radius; private double area; private double diameter; Circle() { } public void setRadius(double r) { } public double getRadius() { } private void computeDiameter() { } private void computeArea() { } public double getDiameter() { } public double getArea() { }}

TestCircle.java

class TestCircle { public static void main (String args[]) { Circle a = new Circle(); Circle b = new Circle(); Circle c = new Circle();

a.setRadius(1.5); b.setRadius(1500.50);

System.out.println("The area of a is" + a.getArea()); System.out.println("The diameter of ais " + a.getDiameter()); System.out.println("The area of b is " + b.getArea()); System.out.println("The diameter of bis " + b.getDiameter()); System.out.println("The area of c is "+ c.getArea()); System.out.println("The diameter of cis " + c.getDiameter()); }}

Programming Exercise 4-6 C Instructions Ll Create a class named circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius() and getRadius (). The setRadius() method not only sets the radius, but it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant for this calculation.) Grading Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade. Once you are happy with your results, click the Submit button to record your score. Circle.java 1 class Circle { 2 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19} 20 TestCircle.java private double radius; private double area; private double diameter; Circle() { } public void setRadius (double r) { } public double getRadius() { } private void computeDiameter() { } private void computeArea() { } public double getDiameter() { } public double getArea() { } +

Step by Step Solution

3.44 Rating (144 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Circlejava class Circle attributes private double radius private double area private double diameter ... View full answer

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!