project created
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.ap;
|
||||
|
||||
public class BasicCalculator implements Calculator {
|
||||
@Override
|
||||
public int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int subtract(int a, int b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int multiply(int a, int b) {
|
||||
return a * b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.ap;
|
||||
|
||||
public interface Calculator {
|
||||
int add(int a, int b);
|
||||
int subtract(int a, int b);
|
||||
int multiply(int a, int b);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.ap;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
ReportGenerator generator = new ReportGenerator();
|
||||
generator.generate(5, 3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ap;
|
||||
|
||||
public class MathHelper {
|
||||
public static int multiply(int a, int b) {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
public static int square(int x) {
|
||||
return x * x;
|
||||
}
|
||||
|
||||
public static int max(int a, int b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ap;
|
||||
|
||||
public class ReportGenerator {
|
||||
public void generate(int x, int y) {
|
||||
Calculator calc = new BasicCalculator();
|
||||
int sum = calc.add(x, y);
|
||||
int diff = calc.subtract(x, y);
|
||||
int product = calc.multiply(x, y);
|
||||
int max = MathHelper.max(x, y);
|
||||
System.out.println("Sum: " + sum + ", Diff: " + diff +
|
||||
", Product: " + product + ", Max: " + max);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
import com.ap.BasicCalculator;
|
||||
import com.ap.Calculator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class CalculatorTest {
|
||||
@Test
|
||||
void testAdd() {
|
||||
Calculator calc = new BasicCalculator();
|
||||
assertEquals(5, calc.add(2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSubtract() {
|
||||
Calculator calc = new BasicCalculator();
|
||||
assertEquals(2, calc.subtract(5, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultiply() {
|
||||
Calculator calc = new BasicCalculator();
|
||||
assertEquals(6, calc.multiply(2, 3));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user