Description
Write a GUI-based program that mimics a calculator. The program should take as input two floating-point numbers and the operation to be performed. It should then output the numbers, the operator, and the result.
The user input should be in the format operand1 operator operand2,
where the operands and the operator are separated by single spaces. For example,
to add 2 and 3, the user should enter 2 + 3
in the text
field of the dialog box.
You should support the following operations: addition (+), subtraction (-), multiplication (*), division (/), and mod (%).
Special cases to handle:
Here's an example run:
Here are a few tips for this program.
Note: You may ONLY use the String methods listed on pp. 80-82 (4th edition) or p. 78 (5th edition) for this assignment. In other words, you may not use other available Java libraries or methods for parsing strings.
Extra Credit:
^
operator to your code. There are Java packages that include the ^
operator,
but you cannot use them for this extra credit. When testing the ^
operator use small numbers!
Note: operand1 ^
operand2 means that
operand1 should be raised to the operand2(th) power. Assume that operand2 is an integer.
Calculator
and your Java source file Calculator.java
.yourlastname_prg2.jar
containing your Java source code.COMP110 Program2 yourlastname
with the following attachments:
yourlastname_prg2.jar
(where yourlastname
is your last name),
which includes your Calculator.java
source fileyourlastname_prg2.txt
(or .doc
),
which has a short write-up of questions you had and/or problems you encountered while doing this assignment
(make sure to include the standard writing assignment header)Print a copy of your code (Calculator.java
) and hand it in at the beginning of class on the due date.
When I run/examine your program, it must satisfy the following requirements. The maximum point value for each is shown in brackets.
Calculator.java
) must be handed in.
JOptionPane
class to create dialog boxes
for user input and output (see Lab 2). Your user input dialog box should contain instructions
for using the program, including a list of the supported operations.