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

Please I need this to be done in Java (eclypse), can I have it answered by anony

ID: 3793957 • Letter: P

Question

Please I need this to be done in Java (eclypse), can I have it answered by anonymous who answered my last question regarding java?

Thank you

You will need to implement a specific algorithm implementation to match the class definition AND implement a unit test using JUnit that conforms the specific naming convention.

Algorithm:

Inputs: integers m and n , assumes m and n are >= 1
Order is not important for this algorithm
Local variables integers:
remainder Initialize:
No initialization required
while(true)
{
    remainder = n modulo m;
    if(remainder == 0)
    {
     break;
     }
     n = m;
    m = remainder
}
return m;

You will need to use the following test data to verify your implementation

m

n

GCD

4567820

2147483640

20

545690876L

3456901294L

2

546587619L

21474836121L

3

951987545L

21474836651L

1

10

5

5

1542354865L

3216548445L

5

-100

325

InvalidParametersException

4951987545L

3216548445L

15

94951987542L

33216548448L

6

import java.util.List;

import org.junit.runner.Result;

import org.junit.runner.notification.Failure;

public class TestHarness

{              public static void main(String[] args)

                {

                testWithStudentTest();

                }

                private static void testWithStudentTest()

                {

                                     try{    Result result = org.junit.runner.JUnitCore.runClasses(Week04JUnitTest.class);

                                                int failCount = result.getFailureCount();

                                                if( failCount > 0 )

                                                { List<Failure> failures = result.getFailures();

                                                                for(Failure fail : failures)

                                                                {

trace("FAILED: " + fail.getMessage());

                                                                }

                                                }              else{

                                                                trace("SUCCESS");

                                                }                             

                                }catch(Exception ex)      {

                                                trace("Unexpected exception: " + ex.getMessage());

                                }

                }

                private static void trace(String msg)

                {                              System.out.println(msg);

                }

}

Turn in

Week04JUnitTest.java, TimedGcd.java

m

n

GCD

4567820

2147483640

20

545690876L

3456901294L

2

546587619L

21474836121L

3

951987545L

21474836651L

1

10

5

5

1542354865L

3216548445L

5

-100

325

InvalidParametersException

4951987545L

3216548445L

15

94951987542L

33216548448L

6

Explanation / Answer

package com.bbp.classes;

import java.util.List;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestHarness
{ public static void main(String[] args)
{
testWithStudentTest();
}
private static void testWithStudentTest()
{
try{ Result result = org.junit.runner.JUnitCore.runClasses(Week04JUnitTest.class);
int failCount = result.getFailureCount();
if( failCount > 0 )
{ List<Failure> failures = result.getFailures();
for(Failure fail : failures)
{
trace("FAILED: " + fail.getMessage());
}
} else{
trace("SUCCESS");
}   
}catch(Exception ex) {
trace("Unexpected exception: " + ex.getMessage());
}
}
private static void trace(String msg)
{ System.out.println(msg);
}
}

package com.bbp.classes;

import static org.junit.Assert.*;

import org.junit.Test;

public class Week04JUnitTest {

   @Test
   public void test() {
   TimedGcd gcd=new TimedGcd(4567820,2147483640);
   gcd.algorithamtest(gcd.getM(), gcd.getN());
  
   }

}

package com.bbp.classes;

public class TimedGcd {
  
   public int m;
   public int n;
  
  
  

   public TimedGcd(int m,int n) {
       this.m=m;
       this.n=n;
   }
  

   public int getM() {
       return m;
   }


   public void setM(int m) {
       this.m = m;
   }


   public int getN() {
       return n;
   }


   public void setN(int n) {
       this.n = n;
   }


   public String toString() {
       return "AlgorithamTest [m=" + m + ", n=" + n + "]";
   }

   public void algorithamtest(int m,int n)
   {
       int remainder=0;
           while(true)
           {
           remainder = n % m;
           if(remainder == 0)
           {
           break;
           }
           n = m;
           m = remainder;
           }
           System.out.println(m);

         
   }

  
}