Use the following code for the next three questions. Assume there is also a Cicl
ID: 3734141 • Letter: U
Question
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();
}
}
Flag this Question
Question 623 pts
What a single statement to declare and instantiate a Square object called mySquare that has a side length of 3.
Flag this Question
Question 633 pts
What a single statement to print to the console the area of the squareyou created above.
Flag this Question
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.
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
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.