COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Part (1) Calculator with JOptionPane
For this part, you are going to develop a simple calculator which have these arithmetic
operators:
● + ⇒ this is addition
● - ⇒ this is minus
● * ⇒ this is multiple
● / ⇒ this is division
● % ⇒ this is not percentage! it is modulus which gives you the reminder
For this part of the assignment you are required to use these techniques:
1. import javax.swing.JOptionPane;
2. methods with a return type of double.
3. while loops
4. Using logical OR operator ||
5. Using logical AND operator &&
6. Use arguments (parameters) for all your methods. (passing your both numbers to the
methods). You are not allowed to define any variable outside of your methods.
“You can use other techniques which you have learnt so far in previous units such as if, else if,
else, etc.”. For this part, you do not need to have the draw () function.
you must create all the following method with the return type of double and use the suggested
names for your methods:
● add (double number1, double number2) for Addition
● minus (double number1, double number2) for Subtraction
● multiply (double number1, double number2) for Multiplication
● divide (double number1, double number2) for Division
● modul (double number1, double number2) for Modulus
You are required only to call one method in your setup (), and that is a void method that is called
process () that has no parameters, you should not have any variables inside your setup.
However, you can create your variables in the process () method. So, your setup () must be
identical to the following code:
void setup ()
{
process ();
}
Your output must be something similar to the figure below after running your program.
Run your program and ask the user to enter the first number:
Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
After pressing OK, your system must show this input message which is asking for choosing
arithmetic operators:
I entered *
After this window your system needs to show the window which asks for the second number:
number 55 has been entered
Now your system must calculate the result and print it like this on the screen:
Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
As you can see the result is 1265.0 which is a double primitive data type.
Next task is to ask your user if he/she wants to continue using your software.
I answered yes in here and kept using the program
So now your system must again ask for the first number
this time you see, there is no welcome message in this window, and number 8.5 has been
entered as the first number.
now it’s the time for asking the arithmetic operator:
Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
we want to divide now
and here we ask for the second number:
and as usual, after clicking on OK button, you can see the result.
Now your system must ask again (your while loop) if you want to continue or not!
Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017