I need help to write a complete java class named circle that stores the radius o
ID: 3643122 • Letter: I
Question
I need help to write a complete java class named circle that stores the radius of a circle and includes the following methods;setRadious(int radius)-sets a new value for radius
circumference()-calculates and returns the radius
area()-calculates and returns the area of the circle
The class should also include a sinle constructor that allows you to set the size of the radius at the beginning. People should be only allowwed to interact with the class through methods meaning it should be declared as private. Additionally, I will nee a short btest program which creates a circle object and demonstrates the use of the methods.
Explanation / Answer
Circle.java public class Circle { // default constructor private int radius; double diameter = 2 * radius; double area = Math.PI * radius * radius; //Create a circle with a radius of 1.0 public double getRadius() { return radius; } public void setRadius(double radius) { radius = radius; } public double getDiameter() { return diameter; } public void setDiameter(double diameter) { diameter = diameter; } public double getArea() { return area; } public void setArea(double area) { area = area; } public double ComputeDiameter(){ return diameter; } public double ComputeArea(){ return area; } } CircleTest.java public class CircleTest { public static void main(String[] args) { Circle myCircle = new Circle(10.0); Circle yourCircle = new Circle(); double radius; double diameter; double area; radius = myCircle.getRadius(); diameter = myCircle.getDiameter(); area = myCircle.getArea(); radius = yourCircle.getRadius(); diameter = yourCircle.getDiameter(); area = yourCircle.getArea(); System.out.println("The area of the circle of radius " + radius + "is " + area + "with a diameter of " + diameter); System.out.println("The area of the circle of radius " + radius + "is " + area + "with a diameter of " + diameter); } } CircleTest.java will not compile. I get this error : CircleTest.java:5: cannot find symbol symbol : constructor Circle(double) location: class Circle Circle myCircle = new Circle(10.0);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.