-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c683188
Showing
3 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>cs435.devops.tutorial</groupId> | ||
<artifactId>devops-tutorial</artifactId> | ||
<packaging>jar</packaging> | ||
<version>0.1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<!-- junit 5, unit test --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.3.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>calculator.Calculator</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import java.util.Scanner; | ||
import java.lang.Math; | ||
|
||
public class Calculator{ | ||
public double add(double x, double y){ | ||
return 0.0; | ||
} | ||
|
||
public double subtract(double x, double y){ | ||
return 0.0; | ||
} | ||
|
||
public double multiply(double x, double y){ | ||
return 0.0; | ||
} | ||
|
||
public double divide(double x, double y){ | ||
return 0.0; | ||
} | ||
|
||
public double squareRoot(double x){ | ||
return 0.0; | ||
} | ||
|
||
public double power(double x, int power){ | ||
return 0.0; | ||
} | ||
|
||
public static void main(String args[]){ | ||
Calculator calculator = new Calculator(); | ||
Scanner scan = new Scanner(System.in); | ||
boolean isRunning = true; | ||
|
||
while(isRunning){ | ||
System.out.print("Please Enter a command: "); | ||
String line = scan.nextLine(); | ||
String[] input = line.split(" "); | ||
|
||
switch(input[0]){ | ||
case "-a": | ||
System.out.print("The sum of " + input[1] + " and " + input[2] + " is: "); | ||
System.out.println(calculator.add(Double.parseDouble(input[1]), Double.parseDouble(input[2]))); | ||
break; | ||
case "-s": | ||
System.out.print("The difference between " + input[1] + " and " + input[2] + " is: "); | ||
System.out.println(calculator.subtract(Double.parseDouble(input[1]), Double.parseDouble(input[2]))); | ||
break; | ||
case "-m": | ||
System.out.print("The product of " + input[1] + " and " + input[2] + " is: "); | ||
System.out.println(calculator.multiply(Double.parseDouble(input[1]), Double.parseDouble(input[2]))); | ||
break; | ||
case "-d": | ||
System.out.print("The quotient of " + input[1] + " and " + input[2] + " is: "); | ||
System.out.println(calculator.divide(Double.parseDouble(input[1]), Double.parseDouble(input[2]))); | ||
break; | ||
case "-r": | ||
System.out.print("The square root of " + input[1] + " is: "); | ||
System.out.println(calculator.squareRoot(Double.parseDouble(input[1]))); | ||
break; | ||
case "-p": | ||
System.out.print(input[1] + " to the power of " + input[2] + " is: "); | ||
System.out.println(calculator.power(Double.parseDouble(input[1]), Integer.parseInt(input[2]))); | ||
break; | ||
default: | ||
isRunning = false; | ||
} | ||
System.out.println(""); | ||
} | ||
scan.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TestCalculator{ | ||
|
||
@Test | ||
public void testAddition(){ | ||
Calculator calculator = new Calculator(); | ||
assertEquals(10, calculator.add(7, 3)); | ||
assertEquals(126, calculator.add(68,58)); | ||
assertEquals(1023, calculator.add(767, 256)); | ||
assertEquals(5, calculator.add(0, 5)); | ||
assertEquals(11, calculator.add(3, 8)); | ||
} | ||
|
||
@Test | ||
public void testSubtraction(){ | ||
Calculator calculator = new Calculator(); | ||
assertEquals(2, calculator.subtract(10, 8)); | ||
assertEquals(58, calculator.subtract(126, 68)); | ||
assertEquals(256, calculator.subtract(1023, 767)); | ||
assertEquals(5, calculator.subtract(5, 0)); | ||
assertEquals(3, calculator.subtract(11, 8)); | ||
} | ||
|
||
@Test | ||
public void testDivision(){ | ||
Calculator calculator = new Calculator(); | ||
assertEquals(4.5, calculator.divide(9, 2)); | ||
assertEquals(42, calculator.divide(126, 3)); | ||
assertEquals(0, calculator.divide(0, 767)); | ||
assertEquals(30.75, calculator.divide(123, 4)); | ||
assertEquals(5.5, calculator.divide(11, 2)); | ||
} | ||
|
||
@Test | ||
public void testMultiplication(){ | ||
Calculator calculator = new Calculator(); | ||
assertEquals(9, calculator.multiply(4.5, 2)); | ||
assertEquals(126, calculator.multiply(42, 3)); | ||
assertEquals(0, calculator.multiply(0, 767)); | ||
assertEquals(123, calculator.multiply(30.75, 4)); | ||
assertEquals(11, calculator.multiply(5.5, 2)); | ||
} | ||
|
||
@Test | ||
public void testSquareRoot(){ | ||
Calculator calculator = new Calculator(); | ||
assertEquals(3, calculator.squareRoot(9)); | ||
assertEquals(4, calculator.squareRoot(16)); | ||
assertEquals(5, calculator.squareRoot(25)); | ||
assertEquals(11, calculator.squareRoot(121)); | ||
assertEquals(12, calculator.squareRoot(144)); | ||
} | ||
|
||
@Test | ||
public void testPower(){ | ||
Calculator calculator = new Calculator(); | ||
assertEquals(9, calculator.power(3, 2)); | ||
assertEquals(64, calculator.power(4,3)); | ||
assertEquals(625, calculator.power(5, 4)); | ||
assertEquals(121, calculator.power(11, 2)); | ||
assertEquals(1728, calculator.power(12, 3)); | ||
} | ||
|
||
|
||
} |