Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create JUnit test cases ( code ) in Eclipse to test the Java code given below. Write the code for test cases for each of

Create JUnit test cases (code) in Eclipse to test the Java code given below. Write the code for test cases for each of the following assertions to test the expected output of each method in math class.
assertEquals(message, expectedValue, value)
assertNotEquals(message, value1, value2)
Calculator Class
package assignment1;
import java.util.Scanner;
public class calculator {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
Math Math = new MathTest();
double answer =0;
double inputA, inputB;
char operator;
boolean done = false;
while (done == false){
System.out.print("Please enter your sum: ");
inputA = input.nextDouble();
operator = input.next().charAt(0);
inputB = input.nextDouble();
switch (operator){
case '+': answer = Math.add(inputA, inputB);
break;
case '-': answer = Math.subtract(inputA, inputB);
break;
case '*': answer = Math.multiply(inputA, inputB);
break;
case '/': answer = Math.divide(inputA, inputB);
break;
case '^': answer = Math.exponent(inputA, inputB);
break;
}
System.out.println(answer);
}
input.close();
package assignment1;
public class doubleMath {
double add(double a, double b){
double answer = a+b;
return answer;
}
double subtract(double a, double b){
double answer = a-b;
return answer;
}
double multiply(double a, double b){
double answer = a*b;
return answer;
}
double divide(double a, double b){
double answer = a/b;
return answer;
}
double power(double a, double b){
double answer =a;
for (int x=2; x<=b; x++){
answer *= a;
}
return answer;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

User Defined Tensor Data Analysis

Authors: Bin Dong ,Kesheng Wu ,Suren Byna

1st Edition

3030707490, 978-3030707491

More Books

Students also viewed these Databases questions

Question

5. Describe the impossible trinity.

Answered: 1 week ago