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.)
a.)
class Circle {
private double radius, diameter, area;
public Circle(){
radius = 1;
calc();
}
public void setRadius(double radius){
this.radius = Math.abs(radius);
calc();
}
public double getRadius(){
return this.radius;
}
public double getDiameter(){
return this.diameter;
}
public double getArea(){
return this.area;
}
private void calc(){
diameter = radius/2;
area = (22/7)*radius*radius;
}
}
b.)
class TestCircle {
public static void main(String... args){
Circle c1 = new Circle();
Circle c2 = new Circle();
Circle c3 = new Circle();
c1.setRadius(2.0932);
c2.setRadius(22.234);
display(c1);
display(c2);
display(c3);
}
public static void display(Circle c){
System.out.println("\nRadius " + c.getRadius());
System.out.println("Diameter" + c.getDiameter());
System.out.println("Area: " + c.getArea());
}
}
class Circle {
private double radius, diameter, area;
public Circle() {
setRadius(1);
}
public void setRadius(double radius) {
this.radius = Math.abs(radius);
calc();
}
public double getRadius() {
return this.radius;
}
public double getDiameter() {
return this.diameter;
}
public double getArea() {
return this.area;
}
private void calc() {
diameter = radius * 2;
area = Math.PI * radius * radius;
}
}
class TestCircle {
public static void main(String... args) {
Circle c1 = new Circle();
Circle c2 = new Circle();
Circle c3 = new Circle();
c1.setRadius(2.0932);
c2.setRadius(22.234);
display(c1);
display(c2);
display(c3);
}
public static void display(Circle c) {
System.out.println("\nRadius: " + c.getRadius());
System.out.println("Diameter: " + c.getDiameter());
System.out.println("Area: " + c.getArea());
}
}

Create a class named Circle with fields named radius, diameter, and area. Include a constructor that...
#include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius; // get function for radius public: double getRadius(){ return radius; } // set function for radius void setRadius(double rad){ radius=rad; } // returning area = 3.14159 * radius * radius double getArea(){ return (3.14159 * radius * radius); } }; // Sample run int main() { // Declaring object of Circle Circle myCircle; myCircle.setRadius(5); // printing radius of circle cout<<"Radius of circle is: "<<(myCircle.getRadius())<<endl;...
C++ 8. Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area...
what are the debuggers in Java? import java.text.NumberFormat; /** * * This class represents a circle that would be used as part * of a larger geometry application */ public class Circle { private double radius; private NumberFormat numberFormat; /** * Constructor for the Circle. * @param radius for the circle */ public Circle(double r) { radius = r; } /** * This method uses the radius of the circle to compute...
Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { } //get method (Accessor Methods ) public double getRadius (...
Create a Java application that allows user to build a Priority Queue of Circle Elements (i.e., priority based on the radius of the circle). The application must be menu controlled similar to Project 4 and provide the following. Allow insertion of a "Circle" object/structure in the Priority Queue data structures. Allow display of all elements from Priority Queue data structure by Invoking a method/function "DisplayPriorityQueue" (uses "DeQueue" method). Allow for deletion of the Queue This is what I have so...
not getting correct values
CENGAGE I MINDTAP Programming Exercise 4-6 | Instructions Circle 5 Create a class named circle with fields named radius , dianeter and area . Include a constructor 6 td ch that sets the radtus to 1 and sp 9 16 calculates the other two values. Also include methods named setRadtus and getRadius() The setRadius() method not only sets the radtus , but it also calculates the other two values. (The diameter of a circle is twice...
Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables...
C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in chapter 10. Some of the...
Please help me to solve this source code. Use the following file: InterfaceRunner.java import java.util.ArrayList; public class InterfaceRunner { public static void main(String[] args) { ArrayList<GeometricSolid> shapes = new ArrayList<>(); shapes.add(new Sphere(10)); shapes.add(new Sphere(1)); shapes.add(new Cylinder(1, 5)); shapes.add(new Cylinder(10, 20)); shapes.add(new RightCircularCone(1, 5)); shapes.add(new RightCircularCone(10, 20)); /* * Notice that the array list holds different kinds of objects * but each one is a GeometricSolid because it implements * the interface. * */ for (GeometricSolid shape : shapes) { System.out.printf("%.2f%n",shape.volume());...
I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a void method named howToColor(). void howToColor(); } GeometricObject class: public class GeometricObject { } Sqaure class: public class Square extends GeometricObject implements Colorable{ //side variable of Square double side; //Implementing howToColor() @Override public void howToColor() { System.out.println("Color all four sides."); } //setter and getter methods for Square public void setSide(double side) { this.side = side; } public double getSide() { return...