Assignment
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
}
}
Question 2: 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.
Question
Write a single statement to print to the console the area of the circle you created above.
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.