diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..b607183
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index b0cbf6e..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-/nbproject/private/
-/build/
-/dist/
-*.class
-
-# Mac OS System
-.DS_Store*
-._*
diff --git a/.project b/.project
new file mode 100644
index 0000000..9b9f376
--- /dev/null
+++ b/.project
@@ -0,0 +1,28 @@
+
+
+ SimpleJavaCalculator
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
+
+ 1692244280313
+
+ 30
+
+ org.eclipse.core.resources.regexFilterMatcher
+ node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
+
+
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/bin/module-info.class b/bin/module-info.class
new file mode 100644
index 0000000..ef51cbd
Binary files /dev/null and b/bin/module-info.class differ
diff --git a/bin/resources/icon/icon-notice.txt b/bin/resources/icon/icon-notice.txt
new file mode 100644
index 0000000..d2577c2
--- /dev/null
+++ b/bin/resources/icon/icon-notice.txt
@@ -0,0 +1 @@
+`icon.png`, all rights reserved by xdvrx1
diff --git a/bin/resources/icon/icon.png b/bin/resources/icon/icon.png
new file mode 100644
index 0000000..527af6f
Binary files /dev/null and b/bin/resources/icon/icon.png differ
diff --git a/bin/simplejavacalculator/BufferedImageCustom.class b/bin/simplejavacalculator/BufferedImageCustom.class
new file mode 100644
index 0000000..ae8edfb
Binary files /dev/null and b/bin/simplejavacalculator/BufferedImageCustom.class differ
diff --git a/bin/simplejavacalculator/Calculator$BiOperatorModes.class b/bin/simplejavacalculator/Calculator$BiOperatorModes.class
new file mode 100644
index 0000000..4aa5cb3
Binary files /dev/null and b/bin/simplejavacalculator/Calculator$BiOperatorModes.class differ
diff --git a/bin/simplejavacalculator/Calculator$MonoOperatorModes.class b/bin/simplejavacalculator/Calculator$MonoOperatorModes.class
new file mode 100644
index 0000000..a2faf44
Binary files /dev/null and b/bin/simplejavacalculator/Calculator$MonoOperatorModes.class differ
diff --git a/bin/simplejavacalculator/Calculator.class b/bin/simplejavacalculator/Calculator.class
new file mode 100644
index 0000000..bbddeb3
Binary files /dev/null and b/bin/simplejavacalculator/Calculator.class differ
diff --git a/bin/simplejavacalculator/SimpleJavaCalculator.class b/bin/simplejavacalculator/SimpleJavaCalculator.class
new file mode 100644
index 0000000..83e029b
Binary files /dev/null and b/bin/simplejavacalculator/SimpleJavaCalculator.class differ
diff --git a/bin/simplejavacalculator/UI.class b/bin/simplejavacalculator/UI.class
new file mode 100644
index 0000000..ed73039
Binary files /dev/null and b/bin/simplejavacalculator/UI.class differ
diff --git a/bin/simplejavacalculatorTest/CalculatorTest.class b/bin/simplejavacalculatorTest/CalculatorTest.class
new file mode 100644
index 0000000..9e950a4
Binary files /dev/null and b/bin/simplejavacalculatorTest/CalculatorTest.class differ
diff --git a/build/built-jar.properties b/build/built-jar.properties
new file mode 100644
index 0000000..5900276
--- /dev/null
+++ b/build/built-jar.properties
@@ -0,0 +1,4 @@
+#Fri, 11 Aug 2023 22:35:15 +0800
+
+
+C\:\\Users\\Clarr\\OneDrive\\Documents\\1.\ Software\ Engineering\ 2020-2022\\A)\ SE\ Studies\\Y3\\S3\\SCC\\Assign\\Assign_2\\SimpleJavaCalculator=
diff --git a/src/module-info.java b/src/module-info.java
new file mode 100644
index 0000000..1c12234
--- /dev/null
+++ b/src/module-info.java
@@ -0,0 +1,11 @@
+/**
+ *
+ */
+/**
+ *
+ */
+module SimpleJavaCalculator {
+ requires java.desktop;
+ requires junit;
+ requires org.junit.jupiter.api;
+}
\ No newline at end of file
diff --git a/src/simplejavacalculator/Calculator.java b/src/simplejavacalculator/Calculator.java
index f76e879..aa9611d 100644
--- a/src/simplejavacalculator/Calculator.java
+++ b/src/simplejavacalculator/Calculator.java
@@ -19,11 +19,11 @@
public class Calculator {
public enum BiOperatorModes {
- normal, add, minus, multiply, divide , xpowerofy
+ normal, add, minus, multiply, divide , xpowerofy, mod
}
public enum MonoOperatorModes {
- square, squareRoot, oneDividedBy, cos, sin, tan, log, rate, abs, ln,
+ square,factorial, squareRoot, oneDividedBy, cos, sin, tan, log, rate, abs, ln,
}
private Double num1, num2;
@@ -52,7 +52,9 @@ private Double calculateBiImpl() {
if (mode == BiOperatorModes.xpowerofy) {
return pow(num1,num2);
}
-
+ if (mode == BiOperatorModes.mod) {
+ return num1 % num2;
+ }
// never reach
throw new Error();
}
@@ -85,6 +87,13 @@ public Double reset() {
public Double calculateMono(MonoOperatorModes newMode, Double num) {
+ if (newMode == MonoOperatorModes.factorial) {
+ double facResult = 1;
+ for(int i=1;i<=num;i++){
+ facResult=facResult*i;
+ }
+ return facResult;
+ }
if (newMode == MonoOperatorModes.square) {
return num * num;
}
diff --git a/src/simplejavacalculator/UI.java b/src/simplejavacalculator/UI.java
index 087bfb1..e1d0252 100644
--- a/src/simplejavacalculator/UI.java
+++ b/src/simplejavacalculator/UI.java
@@ -51,8 +51,8 @@ public class UI implements ActionListener {
private final JTextArea text;
private final JButton but[], butAdd, butMinus, butMultiply, butDivide,
- butEqual, butCancel, butSquareRoot, butSquare, butOneDividedBy,
- butCos, butSin, butTan, butxpowerofy, butlog, butrate, butabs, butBinary, butln;
+ butEqual, butCancel, butSquareRoot, butSquare, butOneDividedBy,butFactorial,
+ butCos, butSin, butTan, butxpowerofy, butlog, butrate, butabs, butBinary, butln, butMod;
private final Calculator calc;
private final String[] buttonValue = {"0", "1", "2", "3", "4", "5", "6",
@@ -96,7 +96,8 @@ public UI() throws IOException {
butMultiply = new JButton("*");
butDivide = new JButton("/");
butEqual = new JButton("=");
- butSquareRoot = new JButton("sqrt");
+ butSquareRoot = new JButton("sqrt");
+ butFactorial = new JButton("!");
butSquare = new JButton("x*x");
butOneDividedBy = new JButton("1/x");
butCos = new JButton("Cos");
@@ -109,7 +110,8 @@ public UI() throws IOException {
butabs = new JButton("abs(x)");
butCancel = new JButton("C");
butBinary = new JButton("Bin");
-
+ butMod = new JButton("%"); // Add the mod button
+
calc = new Calculator();
}
@@ -134,6 +136,7 @@ public void init() {
butEqual.setFont(font);
butSquareRoot.setFont(font);
butSquare.setFont(font);
+ butFactorial.setFont(font);
butOneDividedBy.setFont(font);
butCos.setFont(font);
butSin.setFont(font);
@@ -145,7 +148,8 @@ public void init() {
butabs.setFont(font);
butCancel.setFont(font);
butBinary.setFont(font);
-
+ butMod.setFont(font); // Set font for the mod button
+
panel.add(Box.createHorizontalStrut(100));
panelSub1.add(text);
panel.add(panelSub1);
@@ -163,7 +167,9 @@ public void init() {
panelSub3.add(but[6]);
panelSub3.add(Box.createHorizontalStrut(15));
panelSub3.add(butMultiply);
- panelSub3.add(butDivide);
+ panelSub3.add(butDivide);
+ panelSub3.add(butMod); // Add the mod button here
+
panel.add(panelSub3);
panelSub4.add(but[7]);
@@ -181,6 +187,7 @@ public void init() {
panel.add(panelSub5);
panelSub6.add(butSquare);
+ panelSub6.add(butFactorial);
panelSub6.add(butSquareRoot);
panelSub6.add(butOneDividedBy);
panelSub6.add(butxpowerofy);
@@ -204,6 +211,7 @@ public void init() {
butMinus.addActionListener(this);
butMultiply.addActionListener(this);
butDivide.addActionListener(this);
+ butFactorial.addActionListener(this);
butSquare.addActionListener(this);
butSquareRoot.addActionListener(this);
butOneDividedBy.addActionListener(this);
@@ -215,6 +223,8 @@ public void init() {
butlog.addActionListener(this);
butrate.addActionListener(this);
butabs.addActionListener(this);
+ butMod.addActionListener(this); // Add action listener for the mod button
+
butBinary.addActionListener(this);
butEqual.addActionListener(this);
@@ -268,6 +278,10 @@ public void actionPerformed(ActionEvent e) {
writer(calc.calculateBi(Calculator.BiOperatorModes.xpowerofy, reader()));
}
+ if (source == butFactorial) {
+ writer(calc.calculateMono(Calculator.MonoOperatorModes.factorial, reader()));
+ }
+
if (source == butSquare) {
writer(calc.calculateMono(Calculator.MonoOperatorModes.square, reader()));
}
@@ -299,6 +313,11 @@ public void actionPerformed(ActionEvent e) {
if (source == butabs)
writer(calc.calculateMono(Calculator.MonoOperatorModes.abs, reader()));
+ if (source == butMod) { // Handle the mod button function
+ writer(calc.calculateBi(Calculator.BiOperatorModes.mod, reader()));
+ text.replaceSelection(butMod.getText());
+ }
+
if (source == butEqual)
writer(calc.calculateEqual(reader()));
diff --git a/src/simplejavacalculatorTest/CalculatorTest.java b/src/simplejavacalculatorTest/CalculatorTest.java
index 1ea20f7..f7d16c1 100755
--- a/src/simplejavacalculatorTest/CalculatorTest.java
+++ b/src/simplejavacalculatorTest/CalculatorTest.java
@@ -8,7 +8,15 @@
import simplejavacalculator.Calculator;
-class CalculatorTest {
+class CalculatorTest{
+
+
+ @Test
+ void calculateBiModTest() {
+ Calculator calculator = new Calculator();
+ calculator.calculateBi(Calculator.BiOperatorModes.mod, 7.0);
+ Assertions.assertEquals(3.0, calculator.calculateBi(Calculator.BiOperatorModes.mod, 4.0));
+ }
@Test
void calculateBiNormalTest() {
@@ -79,24 +87,46 @@ void CalculateMonoOneDividedByTest() {
Assertions.assertEquals(0.10, calculator.calculateMono(Calculator.MonoOperatorModes.oneDividedBy, 10.0));
}
+ //Math.cos(π/3)≈ 0.5
@Test
- void CalculateMonoSinTest() {
- Calculator calculator = new Calculator();
- Assertions.assertEquals(0.5, calculator.calculateMono(Calculator.MonoOperatorModes.sin, java.lang.Math.PI / 6), 0.0000000001);
- }
-
- @Test
- void CalculateMonoCosTest() {
- Calculator calculator = new Calculator();
- Assertions.assertEquals(0.5, calculator.calculateMono(Calculator.MonoOperatorModes.cos, java.lang.Math.PI / 3), 0.0000000001);
- }
-
- @Test
- void CalculateMonoTanTest() {
- Calculator calculator = new Calculator();
- Assertions.assertEquals(1.0, calculator.calculateMono(Calculator.MonoOperatorModes.tan, java.lang.Math.PI / 4), 0.0000000001);
- }
-
+ void calculateMonoCosTest() {
+ Calculator calculator = new Calculator();
+ double result = calculator.calculateMono(Calculator.MonoOperatorModes.cos, 60.0);
+ Assertions.assertEquals(Math.cos(Math.toRadians(60.0)), result);
+ }
+
+ //Math.sin(π/6) ≈ 0.5
+ @Test
+ void calculateMonoSinTest() {
+ Calculator calculator = new Calculator();
+ double result = calculator.calculateMono(Calculator.MonoOperatorModes.sin, 30.0);
+ Assertions.assertEquals(Math.sin(Math.toRadians(30.0)), result);
+ }
+
+ //Math.tan(π/4) = 1.0
+ @Test
+ void calculateMonoTanTest() {
+ Calculator calculator = new Calculator();
+ double result = calculator.calculateMono(Calculator.MonoOperatorModes.tan, 45.0);
+ Assertions.assertEquals(Math.tan(Math.toRadians(45.0)), result);
+ }
+
+ //0.0
+ @Test
+ void calculateMonoTanZeroTest() {
+ Calculator calculator = new Calculator();
+ double result = calculator.calculateMono(Calculator.MonoOperatorModes.tan, 0.0);
+ Assertions.assertEquals(0.0, result);
+ }
+
+ //undefined
+ @Test
+ void calculateMonoTanNaNTest() {
+ Calculator calculator = new Calculator();
+ double result = calculator.calculateMono(Calculator.MonoOperatorModes.tan, 90.0);
+ Assertions.assertTrue(Double.isNaN(result));
+ }
+
@Test
void CalculateMonoLogTest() {
Calculator calculator = new Calculator();
@@ -115,5 +145,11 @@ void CalculateMonoAbsTest() {
Assertions.assertEquals(3.0, calculator.calculateMono(Calculator.MonoOperatorModes.abs, -3.0));
Assertions.assertEquals(3.0, calculator.calculateMono(Calculator.MonoOperatorModes.abs, 3.0));
}
+ @Test
+ void calculateMonoFactorialTest() {
+ Calculator calculator = new Calculator();
+ double result = calculator.calculateMono(Calculator.MonoOperatorModes.factorial, 5.0);
+ Assertions.assertEquals(120.0, result);
+ }
-}
+}
\ No newline at end of file