Question

In: Computer Science

Please I need this to be done in Java, can I have it answered by anonymous...

Please I need this to be done in Java, 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

Solutions

Expert Solution

program

package com.ap.beans;

import java.security.InvalidParameterException;
import java.util.Scanner;

public class AlgorithamTest {
  
   public int m;
   public int 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);

         
   }

   public static void main(String[] args) {
       Scanner scanner=new Scanner(System.in);
       System.out.println("enter m value");
       int m=scanner.nextInt();
       System.out.println("enter n value");
   int n=scanner.nextInt();
       AlgorithamTest test=new AlgorithamTest();
       if(m<0||n<0)
       {
           throw new InvalidParameterException();
       }else
          
       test.algorithamtest(m,n);
   }
}

output

enter m value
4567820
enter n value
2147483640
20


Related Solutions

Why are my questions not answered? I am waiting and waiting and desperately need it done....
Why are my questions not answered? I am waiting and waiting and desperately need it done. Here: A new business client comes to your office. There are three owners of the business. The three individuals, Alan, Bob, and Carol, are thinking about forming a partnership. Alan is only investing $1 million in cash. He will not have anything to do with the daily activities of the business. Bob has had some experience in the business and will be responsible for...
Please i need this answered in 10 minutes!! 5. Explain how a technological advance can contribute...
Please i need this answered in 10 minutes!! 5. Explain how a technological advance can contribute to economic growth. Also, explain how better-quality education for young people today can increase economic growth in the future. 6. Suppose that nominal gross domestic product (GDP) in the United States grew by 6%. Given that prices increased by 2% and the population grew by 1%, How much did per capita real GDP grow? In other words, what Is the economic growth rate for...
Hello, I need this done with Java and ran in Eclipse if possible. A university wants...
Hello, I need this done with Java and ran in Eclipse if possible. A university wants to demonstrate its political correctness by applying the Supreme Court’s “Separate but equal is inherently unequal” doctrine to gender as well as race. As such, the university has decided that both genders will use the same bathroom facilities. However, in order to preserve some tradition, it decrees that when a woman is in the bathroom, only other women may enter, and when a man...
I have A B and C answered I only need the answer to D and E....
I have A B and C answered I only need the answer to D and E. I have included the correct answers for A B and C Problem 8-41 (LO. 2, 3, 9) Lori, who is single, purchased 5-year class property for $200,000 and 7-year class property for $400,000 on May 20, 2016. Lori expects the taxable income derived from her business (without regard to the amount expensed under § 179) to be about $800,000. Lori wants to elect immediate...
For the state of New Mexico and Colorado, I need the following questions answered please: a)...
For the state of New Mexico and Colorado, I need the following questions answered please: a) To what extent does New Mexico and Colorado follow the rulings of the Multistate Tax Commission? b) Does New Mexico and Colorado adopt pertinent changes to the Internal Revenue Code? If so, as of what date? c) Is the tax effectiveness of a passive investment company limited in some way? Has New Mexico and Colorado adopted the Geoffrey approach to the taxation of income...
I need this done in JAVA. Define a class named Cash. The class contains the following...
I need this done in JAVA. Define a class named Cash. The class contains the following public elements: A Double stored property that contains the amount of money (dollars and cents) described by an object of the class. A read-only, computed property. It calculates and returns the minimum number of U.S. bills and coins that add up to the amount in the stored property.  The return value is an Int array of length 9 that contains (beginning with index 0 of...
These only need to be short essay answers, I have answered a few already. This is...
These only need to be short essay answers, I have answered a few already. This is due oct. 31st at 11:59 pm ESSAY: RECEIVABLES: Define Accounts Receivable. Accounts Receivable is an account where businesses can keep track of services they have pervaded without the payment from a client. For example, hospitals would use this when journaling the action when a patient is treated without payment. Account Receivables are journaled as increasing with a debit. All of #2 essay questions follow...
I posted this question before and the person who answered it answered wrong.........please have someone else...
I posted this question before and the person who answered it answered wrong.........please have someone else try again The following information applies to the questions displayed below.] O’Brien Company manufactures and sells one product. The following information pertains to each of the company’s first three years of operations: Variable costs per unit: Manufacturing: Direct materials $28 Direct labor $15 Variable manufacturing overhead $5 Variable selling and administrative $3 Fixed costs per year: Fixed manufacturing overhead $580,000 Fixed selling and administrative...
TreeSetDemo IN JAVA PLEASE The following program can be done all in the main method. It...
TreeSetDemo IN JAVA PLEASE The following program can be done all in the main method. It demonstrates that a TreeSet eliminates duplicates and is ordered. Create a Random object with a seed of 5. Create an ArrayList numAL of type Integer Populate numAL with 10 numbers randomly selected from 0 to 6 Print out numAL Create a TreeSet numTS of type Integer Create an Iterator alIter from numAl and use it to add all the elements of numAL in numTS....
I need all the qustions answered if possible please home / study / business / accounting...
I need all the qustions answered if possible please home / study / business / accounting / accounting questions and answers / silven industries, which manufactures and sells a highly successful line of summer lotions ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Silven Industries, which manufactures and sells a highly successful line of summer lotions and in... Silven Industries, which manufactures and sells a highly successful line of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT