-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.java
68 lines (58 loc) · 1.48 KB
/
Calculator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cse360assign3;
/**
* Author: Dhruval Patel
* class: CSE360
* Assignment number: Assignment 3
* Description:
* This class Inherits from AddingMachine to add multiplication, division, and power
* functionality.
*/
public class Calculator extends AddingMachine {
/**
* @description: Constructor for the Calculator class.
*/
public Calculator() {
super(); // Super is called to set total and history to default.
}
/**
* @description: Method that will multiply current rolling value by the parameter
* 'value'.
* @param value {int}
*/
public void multiply(int value) {
total *= value;
history += " * " + value;
}
/**
* @description: Method that divides current rolling value by parameter 'value'.
* If division by zero is attempted, the total rolling value will be set
* equal to zero, but the calculation history will remain.
*
* @param value {int}
*/
public void divide(int value) {
if (value == 0) {
total = 0;
}
else {
total /= value;
}
history += " / " + value;
}
/**
* Method that raises current rolling value by parameter 'value'.
*
* If 'value' is a negative number, the total rolling value will be set to
* zero, but the calculation history will remain.
* @param value {int}
*/
public void power(int value) {
if (value < 0) {
total = 0;
}
else {
total ^= value;
}
history += " ^ " + value;
}
}