JAVA question needs help! Use the following code for the next three questions. A
ID: 3734163 • Letter: J
Question
JAVA question needs help!
Use the following code for the next three questions. Assume there is also a Cicle class (not shown here).
public class Square{
private int sideLength;
public Square(int s) {
sideLength= s;
}
public double getArea() {
return Math.pow(sideLength, 2);
}
public static boolean squareFitsInCircle(Square square, Circle circle) {
return square.getArea() <= circle.getArea();
}
}
Q1
What a single statement to declare and instantiate a Square object called mySquare that has a side length of 3.
Q2.
What a single statement to print to the console the area of the squareyou created above.
Q3
You are given a Circle object called myCircle.
What a single statement to that would go in a separate class (like a driver program) to determine if mySquare can fit inside of myCircle. Store the result in a variable called canFit.
Explanation / Answer
Question 623 pts
What a single statement to declare and instantiate a Square object called mySquare that has a side length of 3.
Answer:
Square mySquare = new Square(3);
Question 633 pts
What a single statement to print to the console the area of the squareyou created above.
Answer:
System.out.println(mySquare.getArea() );
Question 643 pts
You are given a Circle object called myCircle.
What a single statement to that would go in a separate class (like a driver program) to determine if mySquare can fit inside of myCircle. Store the result in a variable called canFit.
Answer:
canFit = mySquare.squareFitsInCircle(mySquare, myCircle);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.