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

looking help for java homework Question1: Write code that would go inside of a h

ID: 3842709 • Letter: L

Question

looking help for java homework

Question1: Write code that would go inside of a handler in a GUI program.

allow the user to type a number into a text field

double the number and display the output to the user

once the display is updated, the user should not be able to enter another number

You do not have to account for the user entering non-numeric input.

Use the following variables:

JTextField numberInputField

JLabel resultOutputLabel

Your code would go here:

public class NumberInputFieldListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

// YOUR CODE HERE

}

}

Question2: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();

}

}

Question

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

Answer:

Question

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

Answer:

Question

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.

Answer:

Explanation / Answer

Question1:

Answer:

JTextField numberInputField

JLabel resultOutputLabel

Your code would go here:

public class NumberInputFieldListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

// YOUR CODE HERE

int number = Integer.parseInt(numberInputField.getText());

resultOutputLabel.setText(""+(number *number ));

}

}

Question

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

Answer: Circle myCircle = new Circle (2);

Question

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

Answer: System.out.println("Area is "+myCircle .getArea());

Question

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.

Answer: boolean canFit = squareFitsInCircle(myCircle, mySquare );