Question: Write a program that uses a WidgetViewer object to do the following: Generate two random integers between 1 and 9 (inclusive). Name one of them

Write a program that uses a WidgetViewer object to do the following:

  • Generate two random integers between 1 and 9 (inclusive). Name one of them x, the other y. Display them to the user using JLabelobjects.
  • Create a JLabel object displaying the text "Enter an operation number."
  • Create a JTextField for the user's input.
  • Create a JButton displaying the text "Press here when you've entered your operation." Use addAndWait to add it to the WidgetViewerobject.

When the user clicks the JButton, evaluate operation in the following order to determine the one and only mathematical operation to perform on x and y. Use a JLabel to display the result.

  • If operation is between 1 and 10 inclusive, add x and y.
  • If operation is evenly divisible by 4, subtract y from x.
  • If operation is evenly divisible by 5, use integer division to divide y into x.
  • If operation is an even number, use floating point division to divide y into x.
  • If none of the other tests on operation apply, multiply x and y.

Note: Operation can be negative or zero.

Note: Put a copy of WidgetViewer.java from the WidgetViewer primer in the folder along with your program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!