Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java 1 3. Implement the following class: Circle +radius : double +color: String

ID: 3708672 • Letter: J

Question

Java 1 3. Implement the following class: Circle +radius : double +color: String + showinformation) +getRadius): double +getArea0 : double +getcircumference) : double Le the method showIntormation () displays 1/ the radus, 2/ the color, 3/ the area, and 4/ the circumference the method getRadius) returns the radius of the circle the method getArea ( ) returns the area ofthe circle. The area of a circle is the ? x radius x radius . the method getCrcunference ( ) returns the circumference of the circle The circumference is ? x radius * 2

Explanation / Answer

Circle.java

public class Circle {

//Declaring instance variable

private double radius;

private String color;

//Zero argumented constructor

public Circle() {

super();

this.radius = 0.0;

this.color="";

}

//Parameterized constructor

public Circle(double radius,String color) {

super();

this.radius = radius;

this.color=color;

}

//Getters and setters

public double getRadius() {

return radius;

}

public void setRadius(double radius) {

this.radius = radius;

}

//This method will return the area of the circle

public double getArea() {

return Math.PI * radius * radius;

}

//This method will return the circumference of the circle

public double getCircumference() {

return 2 * Math.PI * radius;

}

public void showInformation()

{

System.out.println("Radius :"+radius);

System.out.println("Color :"+color);

/* Displaying the area of the circle by

* calling the method on the Circle class object

*/

System.out.printf("Area of the circle :%.2f ",getArea());

  

/* Displaying the circumference of the circle by

* calling the method on the Circle class object

*/

System.out.printf("Circumference of the circle :%.2f",getCircumference());

}

}

__________________

Test.java

import java.text.DecimalFormat;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

double radius;

String color;

//Scanner object is used to get the inputs entered by the user

Scanner sc=new Scanner(System.in);

  

//Getting the radius of the circle

System.out.print("Enter the radius of the circle :");

radius=sc.nextDouble();

System.out.print("Enter Color :");

color=sc.next();

  

//Creating the circle class object by passing the radius as argument

Circle c=new Circle(radius,color);

c.showInformation();

  

}

}

___________________

Output:

Enter the radius of the circle :5.5
Enter Color :Red
Radius :5.5
Color :Red
Area of the circle :95.03
Circumference of the circle :34.56

_______________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote