Skip to content

Commit 2f024f1

Browse files
committed
Added Subtraction with test cases <Incomplete>
1 parent fd36d98 commit 2f024f1

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.zipcodewilmington.scientificcalculator;
22

33
public class Calculator {
4+
private static int result;
5+
46
public static int sum(int firstNum, int secondNum) {
5-
int result;
67
result = firstNum + secondNum;
78
return result;
89
}
10+
11+
public int subtract(int firstNum, int secondNum) {
12+
result = firstNum - secondNum;
13+
return result;
14+
}
915
}

src/main/java/com/zipcodewilmington/scientificcalculator/Console.java renamed to src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Created by leon on 2/9/18.
77
*/
8-
public class Console {
8+
public class CalculatorEngine {
99

1010
public static void print(String output, Object... args) {
1111
System.out.printf(output, args);

src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java renamed to src/main/java/com/zipcodewilmington/scientificcalculator/CalculatorInterface.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@
55
/**
66
* Created by leon on 2/9/18.
77
*/
8-
public class MainApplication {
8+
public class CalculatorInterface {
99
public static void main(String[] args) {
1010

1111
Integer y = 0;
1212
Integer z = 0;
1313

1414
Scanner scanObject = new Scanner(System.in);
1515

16-
Console.println("Welcome to my calculator!");
17-
18-
// Connected the sum method
16+
CalculatorEngine.println("Welcome to the calculator!\nWhat would you like to do?");
17+
System.out.println("1. Basic Functions \n2. Scientific Functions \n3. Something Fun!");
1918

2019
System.out.println("Please enter a number");
2120

2221
y = scanObject.nextInt();
2322
scanObject.nextLine();
2423

2524
// System.out.println(y);
26-
25+
// Connected the sum method
2726
System.out.println("Please enter another number");
2827
z = scanObject.nextInt();
2928
// scanObject.nextLine();
@@ -33,14 +32,14 @@ public static void main(String[] args) {
3332
System.out.println(x);
3433

3534

36-
String s = Console.getStringInput("Enter a string");
35+
String s = CalculatorEngine.getStringInput("Enter a string");
3736

3837

3938

40-
Double d = Console.getDoubleInput("Enter a double.");
39+
Double d = CalculatorEngine.getDoubleInput("Enter a double.");
4140

42-
Console.println("The user input %s as a string", s);
41+
CalculatorEngine.println("The user input %s as a string", s);
4342
// Console.println("The user input %s as a integer", i);
44-
Console.println("The user input %s as a d", d);
43+
CalculatorEngine.println("The user input %s as a d", d);
4544
}
4645
}

src/test/java/com/zipcodewilmington/scientific_calculator/CalculatorEngineTest.java renamed to src/test/java/com/zipcodewilmington/scientific_calculator/CalculatorInterfacesTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88

9-
public class CalculatorEngineTest {
9+
public class CalculatorInterfacesTest {
1010

1111
@Test
1212
public void testSum() {
@@ -32,5 +32,29 @@ public void testSum1() {
3232
Assert.fail();
3333
}
3434
}
35-
}
35+
@Test
36+
public void testSubtract() {
37+
// Given
38+
Calculator calculator = new Calculator();
39+
// When
40+
int result;
41+
result = calculator.subtract(10, 5);
42+
// Then
43+
if (result != 5) { // 10 - 5 = 5
44+
Assert.fail();
45+
}
46+
}
47+
@Test
48+
public void testSubtract1() {
49+
// Given
50+
Calculator calculator = new Calculator();
51+
// When
52+
int result;
53+
result = calculator.subtract(20, 3);
54+
// Then
55+
if (result != 17) { // 20 - 3 = 17
56+
Assert.fail();
57+
}
58+
}
59+
}
3660

0 commit comments

Comments
 (0)