Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Eclipse, create a JAVA jUnit Test - Test Driven Development: Create a test ca

ID: 3815661 • Letter: I

Question

In Eclipse, create a JAVA jUnit Test - Test Driven Development: Create a test case from a measurable requirement.

Consider a method for determining if a method is correctly determining if a number is prime.

example test cases:

public class Savings {

        private final static int maxSize = 100000;

        private int balance;

public Savings() {

            balance = 0;

        }

        public int setbalance(int i) {

            if (i < 0 || i > maxSize) {

                return -1;

            }

            balance = i;

            return 1;

        }

        public int deposit(int i) {

            if (i < 0 || balance + i > maxSize) {

                return -1;

            }

            balance += i;

            return 1;

        }

       public int withdraw(int i) {

            if (i < 0 || balance < i) {

                return -1;

            }

            balance -= i;

            return 1;

        }

public class testSavings {

       @Test // Iteration 1

       public void testSavingsAccount(){

           // Savings f = new Savings();

       }

       @Test //Iteration 2

       public void testDeposit(){

       Savings s = new Savings();

       s.setbalance(0);

       s.deposit(5000);             

       assertEquals(5000, s.balance());

       }

       @Test // Iteration 3   

       public void testWithdraw(){

       Savings s = new Savings();

       s.setbalance(0);

       s.deposit(5000);       

       s.withdraw(3000);     

       assertEquals(2000, s.balance());

       }

Explanation / Answer

Note:
Please add "junit jar" to the code inorder to work.

Code:

public class PrimeExample {
  
   public static boolean isPrimeNumber(int n){
       boolean isPrimeNumber = false;
       int i, m = 0, flag = 0;
       m = n / 2;
       for (i = 2; i <= m; i++) {
           if (n % i == 0) {
               System.out.println("Number is not prime");
               isPrimeNumber = false;
               break;
           }
       }
       if (flag == 0){
           isPrimeNumber = true;
       }
       return isPrimeNumber;
      
   }
   public class testClaas {
       @Test
       public void testD(){
       boolean isPrimeNumber = isPrimeNumber(17);
       assertEquals(true,isPrimeNumber);
       }
      
      
   }
}