代写C++代码 代做C++程序 C++辅导 C++教学

C++网络家教 远程写代码 在线Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

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
this time we enter no or No. (ignore the case in your program)
and by pressing the OK button, your system must show the following message:
Remember that this is not the programming standard exit message. You must have 1 more
message for that.
There is only 1 more thing left! Keep reading...
What if the user didn’t type a correct arithmetic operator? You should have a check for that
somewhere in your code before you ask for your second number.
as you can see the word “asd” is entered instead of a valid operator.
Your program should keep asking the user till a valid arithmetic operator is entered. You can
see that in the dialog box bellow asd is mentioned as a wrong operator in the first line.

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
And after you enter a valid operator it should continue calculation.
End of part 1.
Submit your A3P1.pde to your dropbox.
Continue reading for the next part...

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
Part (2) Look of a fancy calculator with some functionality
○ This is the last part of your assignment 3. In this part, you are going to create a
calculator that looks like” a Windows os or Mac os or a custom one that has five
rows and four columns.” Your calculator does not need to be functional like a
calculator. This means the operators like “+, -, * and /” or numbers do not need to
be working! You just need to create the look of it plus some other small
functionality that will be explained below. For this part, you are required to have
the draw () method and call the other functions in the draw () method.
○ For this section of the assignment you are required to apply the following
techniques:
○ 1. Use of constants and use them correctly
○ 2. Usage of global variable and using it properly
○ 3. Usage of for loops
○ 4. Implementing user defined methods
○ 5. Usage of && operator
○ You can use other techniques that you have learnt so far to show the final output,
but all the requested techniques must be included in your solution.
○ ○
You are required to implement the following methods in your assignment:
○ ● void drawRowsCols ()
○ This method has only one job, and that is drawing horizontal and vertical lines of
your calculator. These lines separate numbers and operators and other
components. You must draw these lines with the usage of for loop/s. Figure
below demonstrate the outcome of this method.

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● void fillNumbers ()
○ The task for this method is to fill up the numbers 0 to 9 using two for loops.
○ Make sure you do not have any number next to 0. This means your first row
from the bottom only contains one number that is 0.
○ The very right column should not contain any numbers. We will put the operators
later in these spots. Figure below demonstrate the outcome of this method
● void fillOperators ()
○ This method fills other operators such as {“+”, “-”, “*”, “/”, “=”, “.”, “sin”, “cos”,
“sqrt” and “AC”}
○ You can put them in different locations if you want to. Or you can follow the same
pattern that the figure below shows:

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● void clearScreen ()
○ This method just draw a white rectangle on the upper space of your calculator
that it is empty and whenever you call this method it looks like you clear the
screen.
○ If the height of the canvas is 700 then this rectangle should occupy 200 px of the
height (two rows).
○ Make sure your rectangle does not have any stroke! The figure below
demonstrates the outcome of this method.

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● void mouseClicked ()
○ This method has two tasks.
■ The first task is, If the user clicks on any of the numbers or operators
(clicks anywhere in five rows and four columns from bottom) then you are
required to have a counter and keep adding up the clicks and show the
updated number on the white space on top. The figure below with three
pictures indicates that the user clicked three times on the keys and the
calculator shows the updated number after each time of clicking.

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● The second task is, if the user clicked on anywhere on the upper side of
the calculator (the space that you did not use for loops to make grids on
it), it would erase the all the numbers. It also will reset your counter to 0.
Figure below is the sample output after clicking in that area.
Some useful information:
● The size of your canvas should be 500 by 700
● The height from 0 to 200 and width from 0 to 500 is reserved for the clearing the text
● The width and height of every column are 125 and 100 respectively.
● You are only allowed to call the following methods in the draw ()
○ drawRowsColsOld ();
○ fillNumbers ();
○ fillOperators ();

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● You can also use a boolean variable in the draw () if you needed. But just one time!
● Call the clearScreen in the mouseClicked () properly. You do not need to call it
anywhere else.
● You can define a proper text size by yourself if it fits in one grid and it is not very small to
see
● The counting should start from the left side of the white rectangle.
End of part 2.
Submit your A3P2.pde to your dropbox.
Continue reading for the next part...
__________________________________
Assignment 3 Grading Guide:
Q1:(Calculator with JOptionPane) (39 marks)
1. Import JOptionPane and use it properly to show messages and get inputs from user (10)
2. Not having any global variables and usage of local variables (2)
3. Usage of while loop to ask if the user wants to keep using the calculator or terminate it.
(5)
4. Usage of while loop to keep asking for a correct operator in case of entering wrong input
as the operator. (5)
5. Usage of logical OR operator || (1)
6. Usage of logical AND operator && (1)
7. Implementing the following user defined method and return a proper value (10)
a. add (double number1, double number2)
b. minus (double number1, double number2)
c. multiply (double number1, double number2)
d. divide (double number1, double number2)
e. modul (double number1, double number2)
8. Following programming standards and adding proper comments for all the blocks (5)
Q3: Look of a Fancy Calculator with Some Functionality (34 marks)
1. Usage of constants and use them properly (2)
2. Usage of global variable and use them properly (2)
3. Implementing the void drawRowsCols () (6)
4. Implementing the void fillNumbers () (6)
5. Implementing the void fillOperators () (6)
6. Implementing the void clearScreen () (3)
7. Implementing the void mouseClicked () (6)
8. Usage of && or || operator (1)
9. Not having additional method calls and declaration in the draw () method. (It is explained
above) (2)

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
Total Marks: 73
The due date is March 14 at 11:30 pm. Remember that the programming standards carry some
marks and do not forget to apply it to your code.
Don’t forget to be active in the discussion forums and ask your questions. It DOES help a lot!

相关推荐