Question
Change the below code in Java using JOptionPane and make sure displaying radius, area, and circumference of the circle should work nicely. Circle.java import java.text.DecimalFormat;
Change the below code in Java using JOptionPane and make sure displaying radius, area, and circumference of the circle should work nicely.
Circle.java
import java.text.DecimalFormat;
public class Circle extends Point {
//Declaring instance variables private double radius; //Zero Argumented constructor public Circle() { this.radius=0.0; } //Parameterized constructor public Circle(int x, int y,double radius) { super(x, y); setRadius(radius); } //Getter and Setter methods public double getRadius() { return radius; } public void setRadius(double radius) { if(radius>=0) this.radius = radius; else { System.out.println("Invalid.Radius Must be Positive."); radius=0.0; } } public double calArea() { return Math.PI*getRadius()*getRadius(); } public double calCircum() { return 2*Math.PI*getRadius(); } /* toString() method which displays * the contents of an object inside it */ @Override public String toString() { DecimalFormat df=new DecimalFormat("#.##"); System.out.println(super.toString()); return "Circle# Radius=" + radius + " Area of Circle ="+df.format(calArea()); return " Circle # Radius =" + radius + " Circumference of Circle ="+df.format(calCircum());
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started