179,126 views
1 vote
1 vote
Create a class called Circle, which has (i) an attribute radius, (ii) a method that returns the current radius of a circle object, (iii) a method that allows the user to reset the radius of a circle, (iv) a method that calculates the area of the circle, and (v) a constructor that takes a number as parameter input and assign the number as the initial value of radius.

User Tom Gijselinck
by
2.9k points

1 Answer

3 votes
3 votes

Answer:

Step-by-step explanation:

The following class is written in Java. I created the entire Circle class with each of the methods and constructor as requested. I also created a tester class to create a circle object and call some of the methods. The output can be seen in the attached picture below for the tester class.

class Circle {

double radius;

public Circle(double radius) {

this.radius = radius;

}

public double getRadius() {

return radius;

}

public void resetRadius() {

radius = 0;

}

public double calculateArea() {

double square = Math.pow((Math.PI * radius), 2);

return square;

}

}

Create a class called Circle, which has (i) an attribute radius, (ii) a method that-example-1
User Ruhanbidart
by
3.4k points