Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Justin b #104

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@
<groupId>com.zipcodewilmington</groupId>
<artifactId>scientific_calculator</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.zipcodewilmington.scientificcalculator;

//comments

public class CalculatorOperator {

public static double addition (double a, double b) {
double addition = a + b;
return addition;
}

public static double subtraction
(double a, double b) {
double subtraction = a - b;
return subtraction;
}

public static double multiplication (double a, double b) {
double multiplication = a * b;
return multiplication;
}

public static double division (double a, double b) {
double division = a / b;
return division;
}

public static double square (double a) {
double square = Math.pow(a,2);
return square;
}

public static double squareRoot (double a) {
double squareRoot = Math.sqrt(a);
return squareRoot;
}

public static double exponents (double a, double b) {
double exponent = Math.pow(a,b);
return exponent;
}

public static double multiplicativeInverse (double a) {
double multiplicativeInverse = 1/a;
return multiplicativeInverse;
}

public static double additiveInverse (double a) {
double additiveInverse = a * -1;
return additiveInverse;
}

}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zipcodewilmington.scientificcalculator;

// comments

import java.util.Scanner;

/**
Expand All @@ -23,10 +25,16 @@ public static String getStringInput(String prompt) {
}

public static Integer getIntegerInput(String prompt) {
return null;
Scanner scanner = new Scanner(System.in);
println(prompt);
int userInput = scanner.nextInt();
return userInput;
}

public static Double getDoubleInput(String prompt) {
return null;
Scanner scanner = new Scanner(System.in);
println(prompt);
double userInput = scanner.nextDouble();
return userInput;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
package com.zipcodewilmington.scientificcalculator;

// comments

/**
* Created by leon on 2/9/18.
*/
public class MainApplication {
public static void main(String[] args) {
Console.println("Welcome to my calculator!");
String s = Console.getStringInput("Enter a string");
Integer i = Console.getIntegerInput("Enter an integer");
Double i = Console.getDoubleInput("Enter a double");
Double d = Console.getDoubleInput("Enter a double.");

Console.println("The user input %s as a string", s);
Console.println("The user input %s as a integer", i);
Console.println("The user input %s as a d", d);
}
}

public static double calculator (String s, double i, double d) {
double result = 0;
switch (s) {
case "+":
result = CalculatorOperator.addition(i, d);
break;
case "-":
result = CalculatorOperator.subtraction(i, d);
break;
case "*":
result = CalculatorOperator.multiplication(i, d);
break;
case "/":
result = CalculatorOperator.division(i,d);
break;
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
package com.zipcodewilmington.scientific_calculator;

import com.zipcodewilmington.scientificcalculator.CalculatorOperator;
import com.zipcodewilmington.scientificcalculator.MainApplication;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;


/**
* Created by leon on 2/9/18.
*/
public class TestMainApplication {
@Test
public void addition() {
Assertions.assertEquals(6 , CalculatorOperator.addition(3, 3));
}

@Test
public void subtraction() {
Assertions.assertEquals(-1 , CalculatorOperator.subtraction(3, 4));
}

@Test
public void multiplication() {
Assertions.assertEquals(17 , CalculatorOperator.multiplication(17, 1));
}

@Test
public void division() {
Assertions.assertEquals(1 , CalculatorOperator.division(22, 22));
}

@Test
public void squareTest() {
Assertions.assertEquals(9 , CalculatorOperator.square(3));
}

@Test
public void squareRootTest() {
Assertions.assertEquals(5 , CalculatorOperator.squareRoot(25));
}

@Test
public void exponentsTest() {
Assertions.assertEquals(4 , CalculatorOperator.exponents(2,2));
}

@Test
public void multiplicativeInverseTest() {
Assertions.assertEquals(1 , CalculatorOperator.multiplicativeInverse(1));
}

@Test
public void additiveInverseTest() {
Assertions.assertEquals(4 , CalculatorOperator.additiveInverse(-4));
}

@Test
public void calculatorTest() {
Assertions.assertEquals(5.2 , MainApplication.calculator("+", 2.2, 3.0));
Assertions.assertEquals(-1 , MainApplication.calculator("-", 2.0, 3.0));
Assertions.assertEquals(6 , MainApplication.calculator("*", 2.0, 3.0));
Assertions.assertEquals(4 , MainApplication.calculator("/", 12, 3));
}


}