Download presentation
Presentation is loading. Please wait.
1
Android 11: The Calculator Assignment
Kirk Scott
4
Introduction This set of overheads covers the information in the assignment sheet for the calculator app Rather than depending on the overheads, which are just for in-class presentation, you should follow the sheet when working on the assignment
5
Notice this one, overriding principle for the calculator assignment:
Your app should be able to handle anything that the user does with it—even if the input is incorrect—without crashing One way or the other, whether through if statements, exception catching, or whatever, the app should be able to handle anything that’s done with it
6
Outline There is no real outline for this set of overheads
It is simply the complete contents of the assignment check-off sheet
7
Android Assignment 2 Check Off Sheet
Name:___________________________ Total out of 150: _____
8
The outcome of assignment 2 is a calculator app.
You may want to refer back to assignment 1 for some ideas on what this is about. You will notice that this assignment doesn’t come with a screen shot. A screen shot would be slightly misleading, because it would only show one of several different layouts and implementations.
9
On this assignment, each student will get a separate set of specifications.
It’s important to make sure that you do a layout and implementation that follow your specifications, and don’t mistakenly do something else.
10
Visually, the app will be divided into these parts:
1. The buttons representing the number keys of a 10 key calculator plus the decimal point so that doubles as well as integers can be entered. 2. The buttons for the different operators, including +, -, *, /, and others.
11
3. Two text boxes. These are the boxes where the user will enter operands.
The boxes should be labeled “operand 1” and “operand 2”. 4. One text box labeled “result” and a button with the “=” sign on it. This is where the result of a calculation will be shown.
12
The parts of the assignment are given below, with a point breakdown, so that it will be clear how grading will be done.
13
The first observation is this:
No points will be given for your assignment if it does not follow the individual specifications you were given. This covers the particular operator you are asked to include, and it covers the placement of the 4 groups of visual elements in the upper left (UL), upper right (UR), lower left (LL), and lower right (LR), respectively.
14
Part 0. First specification check: Which operator did you implement?
____ 0 pts. Square Root (sqrt) or Natural Logarithm (ln) operator.
15
Part I. Points for displaying the visual elements of the app, assuming that they are in the correct position. ____ 5 pts Keypad and decimal point UL UR LL LR ____ 5 pts Operator buttons UL UR LL LR ____ 5 pts Operand boxes and labels UL UR LL LR ____ 5 pts Result box and “=” button UL UR LL LR ____ Group 1, subtotal out of 20 ******* In order to get points for the rest of the assignment, item 0 has to be checked off as correct, and full points have to be given for items 1-4, indicating that you implemented your individual specifications as given. *******
16
Part II. Points for functionality.
Overall, note that the calculator should be able to work on both ints and doubles, that is values entered into it which may or may not have decimal points. It should also work on positive and negative numbers.
17
The boxes for the operands and result should be simple text boxes, not editable boxes.
In other words, tapping on them should not bring up the Android keyboard. The only way that values can be put into them is by using the 10 key keypad or, for negative numbers, by using the “-“ operator button.
18
In general, the calculator app should also behave “gracefully” if the user tries to enter an unsuitable value. In other words, user input should not be able to crash the calculator. Instead, the calculator should print out a message explaining what’s wrong and let the user try again.
19
+, -, *, and / are binary operators.
The calculator should work in this way for binary operators: The user enters the first operand. The calculator should display this in the operand 1 box. Then the user presses the desired binary operator.
20
The user then enters the second operand.
The calculator should display this in the operand 2 box. Then the user presses the “=” button. The calculator should display the result of the calculation in the result box.
21
The inverse, 1/x, operator and the factorial operator, n
The inverse, 1/x, operator and the factorial operator, n!, are unary operators. Everyone will be expected to implement these. The Square Root and Natural Logarithm operators are also unary. Your specifications will ask you to implement only one of these two operators.
22
The calculator should work in this way for unary operators:
The user enters the operand. The calculator should display this in the operand 1 box. Then the user presses the desired unary operator. The calculator should display the result of the operation in the result box.
23
You are also asked to implement a Clear button (C).
It is not really an operator, but when doing your layout, you should group the Clear button with the operator buttons. The Clear button should work in this way: When the user presses the Clear button, any contents of the operand 1, operand 2, and result boxes should be removed.
24
The Clear button should also zero out any corresponding variables.
In other words, suppose you were midstream in a binary operation and you had already entered the first operand. If you then pressed the Clear button, make sure that if a variable is holding the value of the first operand, it is zeroed out. Anything entered before pressing the Clear button should be gone, and should have no effect on any subsequent operation.
25
******* Note that there are no specific points shown on this check-off sheet for values appearing in the operand boxes when numeric buttons, the decimal point button, or the minus sign button are clicked. It is assumed that this is necessary for a correctly functioning calculator. You won’t get credit for the arithmetic operations listed below unless values appear in the operand and result boxes as expected. *******
26
******* Note that this is the general rule for invalid input, exception handling, etc., which applies to all of the arithmetic operations given below: You will lose points for any cases which would cause your app to crash. That is the unforgivable sin.
27
If mathematically invalid input is entered, there are basically three possible cases:
1) You decide to try to deal with invalid input with if statements. 2) You decide to deal with it by catching an exception. 3) You recognize that Java will give a result of “Infinity” or “NaN” (not a number)—which may be a little questionably mathematically—but which isn’t a runtime error.
28
Any combination of these three options is OK for various different kinds of invalid input.
The situation where you will lose points is an implementation where some action causes the app to crash. *******
29
5. Addition ____ 5 pts. Addition works 6. Addition with negative operands and decimal points. ____ 5 pts. You can enter negative operands and addition works. ____ 5 pts. You can enter values with decimal points and addition works. ____ 5 pts. Error handling will be tested by entering a value with more than one decimal point and trying to add. The calculator should catch the problem, print a message, and let you continue, rather than crashing. *** Note that the grading principle is that if you got these things to work for addition, they won’t have to be separately tested for the other arithmetic operators.
30
7. Subtraction ____ 10 pts. Subtraction works 8. Multiplication ____ 10 pts. Multiplication works
31
9. Division ____ 10 pts. Division works. *** Note that the points for division are all-or-nothing. Included in this is division by 0. Not only should regular division be done correctly, but division by 0 should not cause the calculator to crash. It is acceptable to simply show a value of “Infinity”, which is the system return for division by 0 in various cases. It is also acceptable to catch the exception and print out an explanatory message.
32
10. Factorial ____ 5 pts. Factorial (n!) works ____ 5 pts. Factorial should not give any kind of numeric result for input < 0 or non-integer input. *** It is possible that your code will give NaN (Java for “not a number”). If so, that is acceptable output. Alternatively, your code should detect invalid input, an explanatory message should be shown to the user, and the calculator should not crash.
33
11. Clear ____ 5 pts. Clear blanks out the operand and result boxes ____ 5 pts. Operations after clear aren’t affected by previous input
34
12. Square Root or Natural Logarithm
____ 5 pts. Square Root or Natural Logarithm works ____ 5 pts. Square root should not give any kind of numeric result for input < 0. Natural logarithm should not give any kind of numeric result for input <= 0. *** It is possible that your code will give NaN (Java for “not a number”). If so, that is acceptable output. Alternatively, your code should detect invalid input, an explanatory message should be shown to the user, and the calculator should not crash. ____ Group 2, subtotal out of 80
35
Part III. Points for user interface features.
The remaining 50 points for the assignment come from implementing any 5 user interface features which you add to the app. These features do not have to have any useful functionality related to the calculator app.
36
However, in order to have just one thing to demonstrate for grading purposes, they have to be included in the calculator app. If you can figure out a way to make them meaningful to the app, that’s great, but there are no additional points for that.
37
The kinds of features which you can include were covered in the overheads on topics like input controls, menus, dialogs, notifications, toasts, etc. Anything covered there, or elsewhere, which can be visually recognized and individually identified will count as one of the items under this heading.
38
(For example, you could implement a spinner. That would count.
Having two different values shown in the spinner would not count as two separate items.)
39
____ 10 pts. 13. User interface feature 1
____ Group 3, subtotal out of 50 ____ Grand total out of 150
40
Summary and Mission Go forth, be fruitful, and multiply
41
The End
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.