(Solved) : Using Java Design Code Swing Gui Calculator Calculator Two Text Fields User Cannot Change Q42790905 . . .

Using Java

Design and code a Swing GUI calculator. Your calculator willhave two text fields that the user cannot change: One labeled”Result” will contain the result of performing the operation, andthe other labeled “Operand” will be for the user to enter a numberto be added, subtracted, and so forth from the result. The userenters the number for the “Operand” text field by clicking buttonslabeled with the digits 0 through 9 and a decimal point, just as ina real calculator. Allow the operations of addition, subtraction,multiplication, and division. Use a GridLayoutmanager to produce a button pad that looks similar to the keyboardon a real calculator.

When the user clicks a button for an operation, the followingoccurs:

  • the operation is performed,
  • the “Result” text field is updated,
  • the “Operand” text field is cleared.

Include a button labeled “Reset” that resets the “Result” to 0.0. Also include a button labeled “Clear” that resets the “Operand”text field so it is blank.

Hint: Define an exception class namedDivisonByZeroException. Have your code throw andcatch a DivisonByZeroException if the userattempts to “divide by zero.” Your code will catch theDivisonByZeroException and output a suitablemessage to the “Operand” text field. The user may then enter a newsubstitute number in the “Operand” text field. Because values oftype double are, in effect, approximate values, itmakes no sense to test for equality with 0.0. Consider an operandto be “equal to zero” if it is in the range -1.0e-10 to+1.0e-10.

Some sample screens for using a calculator are shown below, butagain, feel free to design the look of your own calculator.

Beginning display:

Chriss Calculator 0 x Operand Enter numbers here. Result 00 U n Reset clear 1- .

Enter “3”, “3”, “3”, “3”, “3”, and “+”

Chriss Calculator DO X Operand Result 33333.0 E Reset clear

Enter “6” and “/”

Chriss Calculator 100 x Operand Result 5555.5 Clear + |* Reset .

Enter “0” and “/”

Chriss Calculator Operand Division by zero! Result 5555.5 + L. * Reset Clear

Submit program files for all classes, as well as PrintScreensshowing the calculator in various states, including a divisionby zero.

Chris’s Calculator 0 x Operand Enter numbers here. Result 00 U n Reset clear 1- . Chris’s Calculator DO X Operand Result 33333.0 E ‘ Reset clear Chris’s Calculator 100 x Operand Result 5555.5 Clear + |* Reset . Chris’s Calculator Operand Division by zero! Result 5555.5 + L. * Reset Clear Show transcribed image text Chris’s Calculator 0 x Operand Enter numbers here. Result 00 U n Reset clear 1- .
Chris’s Calculator DO X Operand Result 33333.0 E ‘ Reset clear
Chris’s Calculator 100 x Operand Result 5555.5 Clear + |* Reset .
Chris’s Calculator Operand Division by zero! Result 5555.5 + L. * Reset Clear

Expert Answer


Answer to Using Java Design and code a Swing GUI calculator. Your calculator will have two text fields that the user cannot change…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?