Skip to content

Commit 6213418

Browse files
authored
Merge pull request #3 from SiowYenChong/dev#1
Dev#1
2 parents dae8fe0 + 21a4657 commit 6213418

File tree

7 files changed

+30
-3
lines changed

7 files changed

+30
-3
lines changed

.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@
1414
<natures>
1515
<nature>org.eclipse.jdt.core.javanature</nature>
1616
</natures>
17+
<filteredResources>
18+
<filter>
19+
<id>1692244280313</id>
20+
<name></name>
21+
<type>30</type>
22+
<matcher>
23+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
24+
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25+
</matcher>
26+
</filter>
27+
</filteredResources>
1728
</projectDescription>

bin/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/simplejavacalculator/
54 Bytes
Binary file not shown.
139 Bytes
Binary file not shown.

bin/simplejavacalculator/UI.class

157 Bytes
Binary file not shown.

src/simplejavacalculator/Calculator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum BiOperatorModes {
2323
}
2424

2525
public enum MonoOperatorModes {
26-
square, squareRoot, oneDividedBy, cos, sin, tan, log, rate, abs, ln,
26+
square,factorial, squareRoot, oneDividedBy, cos, sin, tan, log, rate, abs, ln,
2727
}
2828

2929
private Double num1, num2;
@@ -85,6 +85,13 @@ public Double reset() {
8585

8686

8787
public Double calculateMono(MonoOperatorModes newMode, Double num) {
88+
if (newMode == MonoOperatorModes.factorial) {
89+
double facResult = 1;
90+
for(int i=1;i<=num;i++){
91+
facResult=facResult*i;
92+
}
93+
return facResult;
94+
}
8895
if (newMode == MonoOperatorModes.square) {
8996
return num * num;
9097
}

src/simplejavacalculator/UI.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class UI implements ActionListener {
5151
private final JTextArea text;
5252

5353
private final JButton but[], butAdd, butMinus, butMultiply, butDivide,
54-
butEqual, butCancel, butSquareRoot, butSquare, butOneDividedBy,
54+
butEqual, butCancel, butSquareRoot, butSquare, butOneDividedBy,butFactorial,
5555
butCos, butSin, butTan, butxpowerofy, butlog, butrate, butabs, butBinary, butln;
5656
private final Calculator calc;
5757

@@ -96,7 +96,8 @@ public UI() throws IOException {
9696
butMultiply = new JButton("*");
9797
butDivide = new JButton("/");
9898
butEqual = new JButton("=");
99-
butSquareRoot = new JButton("sqrt");
99+
butSquareRoot = new JButton("sqrt");
100+
butFactorial = new JButton("!");
100101
butSquare = new JButton("x*x");
101102
butOneDividedBy = new JButton("1/x");
102103
butCos = new JButton("Cos");
@@ -134,6 +135,7 @@ public void init() {
134135
butEqual.setFont(font);
135136
butSquareRoot.setFont(font);
136137
butSquare.setFont(font);
138+
butFactorial.setFont(font);
137139
butOneDividedBy.setFont(font);
138140
butCos.setFont(font);
139141
butSin.setFont(font);
@@ -181,6 +183,7 @@ public void init() {
181183
panel.add(panelSub5);
182184

183185
panelSub6.add(butSquare);
186+
panelSub6.add(butFactorial);
184187
panelSub6.add(butSquareRoot);
185188
panelSub6.add(butOneDividedBy);
186189
panelSub6.add(butxpowerofy);
@@ -204,6 +207,7 @@ public void init() {
204207
butMinus.addActionListener(this);
205208
butMultiply.addActionListener(this);
206209
butDivide.addActionListener(this);
210+
butFactorial.addActionListener(this);
207211
butSquare.addActionListener(this);
208212
butSquareRoot.addActionListener(this);
209213
butOneDividedBy.addActionListener(this);
@@ -268,6 +272,10 @@ public void actionPerformed(ActionEvent e) {
268272
writer(calc.calculateBi(Calculator.BiOperatorModes.xpowerofy, reader()));
269273
}
270274

275+
if (source == butFactorial) {
276+
writer(calc.calculateMono(Calculator.MonoOperatorModes.factorial, reader()));
277+
}
278+
271279
if (source == butSquare) {
272280
writer(calc.calculateMono(Calculator.MonoOperatorModes.square, reader()));
273281
}

0 commit comments

Comments
 (0)