diff --git a/.gitignore b/.gitignore index a1c2a238a965f004ff76978ac1086aa6fe95caea..23df5e06198b8cd01768cb5dadc4c1b319f15aba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea # Compiled class file *.class diff --git a/maven_work01/maven_work01.iml b/maven_work01/maven_work01.iml new file mode 100644 index 0000000000000000000000000000000000000000..156f690606612a5716a4f19a32948b4f8dfd5bb0 --- /dev/null +++ b/maven_work01/maven_work01.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/maven_work01/pom.xml b/maven_work01/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..8acdae8134e4aacdd37796c46f2e4c8598983189 --- /dev/null +++ b/maven_work01/pom.xml @@ -0,0 +1,73 @@ + + + 4.0.0 + + com.yyy + javase_01 + 1.0-SNAPSHOT + + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + private + true + UTF-8 + UTF-8 + UTF-8 + none + + + + date + a + + + + + + compile + + jar + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.0 + + + package + + shade + + + + + com.yyy.Main + + + + + + + + + + \ No newline at end of file diff --git a/maven_work01/src/main/java/com/yyy/Main.java b/maven_work01/src/main/java/com/yyy/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..324fa42f39dad715cab89b21f11a69dfcbdc18e5 --- /dev/null +++ b/maven_work01/src/main/java/com/yyy/Main.java @@ -0,0 +1,9 @@ +package com.yyy; + +public class Main { + public static void main(String[] args) { + System.out.println(work01.calculate(3, '*', 1)); + work02.printMessage("hello world"); + work03.printMessage("work03"); + } +} diff --git a/maven_work01/src/main/java/com/yyy/work01.java b/maven_work01/src/main/java/com/yyy/work01.java new file mode 100644 index 0000000000000000000000000000000000000000..b3496f1d80ae4172451228936d5a6ed8a01a1de7 --- /dev/null +++ b/maven_work01/src/main/java/com/yyy/work01.java @@ -0,0 +1,30 @@ +package com.yyy; + +import java.util.Scanner; +public class work01 { + public static double calculate(double num1, char operator, double num2) { + double result = 0.0; + switch (operator) { + case '+': + result = num1 + num2; + break; + case '-': + result = num1 - num2; + break; + case '*': + result = num1 * num2; + break; + case '/': + if (num2 != 0) { + result = num1 / num2; + } else { + System.out.println("除数不能为0"); + return Double.NaN; + } + break; + default: + System.out.println("无效的运算符"); + } + return result; + } +} diff --git a/maven_work01/src/main/java/com/yyy/work02.java b/maven_work01/src/main/java/com/yyy/work02.java new file mode 100644 index 0000000000000000000000000000000000000000..7d10f1b183ad293a81da359b9a96c99ec98ac478 --- /dev/null +++ b/maven_work01/src/main/java/com/yyy/work02.java @@ -0,0 +1,7 @@ +package com.yyy; + +public class work02 { + public static void printMessage(String message) { + System.out.println(message); + } +} diff --git a/maven_work01/src/main/java/com/yyy/work03.java b/maven_work01/src/main/java/com/yyy/work03.java new file mode 100644 index 0000000000000000000000000000000000000000..d2012d900ae0bf52266582bbe2f5a9d3284f955e --- /dev/null +++ b/maven_work01/src/main/java/com/yyy/work03.java @@ -0,0 +1,7 @@ +package com.yyy; + +public class work03 { + public static void printMessage(String message) { + System.out.println(message); + } +} diff --git a/maven_work01/src/test/java/com/yyy/work01Test.java b/maven_work01/src/test/java/com/yyy/work01Test.java new file mode 100644 index 0000000000000000000000000000000000000000..5e72f988c04297004c830fbd3cff1592d874bb03 --- /dev/null +++ b/maven_work01/src/test/java/com/yyy/work01Test.java @@ -0,0 +1,36 @@ +package com.yyy; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + + +//@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class work01Test { + @Test + public void testAddition() { + Assert.assertEquals(5.0, work01.calculate(2.0, '+', 3.0), 0.001); + System.out.println(work01.calculate(2.0, '+', 3.0)); + } + + @Test + public void testSubtraction() { + Assert.assertEquals(4.0, work01.calculate(7.0, '-', 3.0), 0.001); + System.out.println(work01.calculate(7.0, '-', 3.0)); + } + + @Test + public void testMultiplication() { + Assert.assertEquals(15.0, work01.calculate(5.0, '*', 3.0), 0.001); + System.out.println(work01.calculate(5.0, '*', 3.0)); + } + + @Test + public void testDivision() { + Assert.assertEquals(4.0, work01.calculate(12.0, '/', 3.0), 0.001); + System.out.println(work01.calculate(12.0, '/', 3.0)); + } + + +}