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

Use the following code for the next three questions. Assume there is also a Squa

ID: 3594941 • Letter: U

Question

Use the following code for the next three questions. Assume there is also a Square class (not shown here).

public class Circle{

private int diameter;

public Circle(int d)   {

diameter = d;

}

public double getArea()   {

return Math.PI * Math.pow( (diameter / 2), 2);

}

public static boolean squareFitsInCircle(Circle circle, Square square) {

return square.getArea() <= circle.getArea();

}

}

What a single statement to declare and instantiate a Circle object called myCircle that has a diameter of 4.

What a single statement to print to the console the area of the circle you created above.

You are given a Square object called mySquare.

What a single statement to that would go in a separate class (like a driver program) to determine whether mySquare can fit inside of myCircle. Store the result in a variable called canFit.

Explanation / Answer

Circle.java

public class Circle {
//Declaring instance variable
private int diameter;

//Parameterized constructor
public Circle(int d) {
diameter = d;
}

//Method which calculates the area of the Circle
public double getArea() {
return Math.PI * Math.pow((diameter / 2), 2);
}

//Method which checks whether the Square fits inside circle
public static boolean squareFitsInCircle(Circle circle, Square square) {
return square.getArea() <= circle.getArea();
}
}

________________

Square.java

public class Square {

//Declaring instance variables
private double side;

//Parameterized constructor
public Square(double side) {
super();
this.side = side;
}

//Method which calculates the area of the Square
public double getArea() {
return side * side;
}
}

________________

Output:

Area of the Circle :12.566370614359172
Square Fits inside Circle

_____________Could you rate me well.Plz .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