1. Engineering
  2. Computer Science
  3. hello i need help writing this java program please here...

Question: hello i need help writing this java program please here...

Question details

Hello i need help writing this java program please!

The Power Analyzer Program The PowerAnalyzer class wi consist of only one method, the main. The main method will perform the following tasks: 1. It prompts the user to enter the base of a power 2. It prompts the user to enter the exponent of a power 3. It computes the powers using both the fast and naive algorithms and displays the powers. 4. It randomly generates a four-digit positive integer for the base of a 5. It randomly generates a two-digit positive integer for the exponent of 6. Similarly, it computes the powers using these randomly 7. It prompts the user for a positive integer to be used as the base in power. a power tegers and both the fast and naive algorithms and displays the powers. measuring and displaying runtimes for generating various powers of the base. 8. For n- 16,32, 64, 128, 256,512, 1024, 2048, 4096,8192), your program will compute, using the naive and fast exponentiation algorithms, pow- ers of the base entered by the user and measure and display the exe cution times in nanoseconds for these algorithms as shown in the table in the sample runSample Run Enter the base of the power -2 Enter the exponent of the power -> 100 Using Naive Algorithm: 2*100 1267650600228229401496703205376 Using Fast Algorithm: 2*100 - 1267650600228229401496703205376 Using a random 4-digit base and a random 2-digit exponent Using Naive Algorithm: 6362 24 - . . . . Using Fast Algorithm: 6362 24- . Enter the base of the powers for the table 546879 b-546879 bn: Fast Power(ns) bn: Naive Power (ns) 16 32 64 128 256 512 1024 2048 4096 8192

Here is the starter code

import poweranalyzer;
import java.math.BigInteger;

/*
* Provides implementations for a naive and a fast power method for
* BigIntegers types with integer exponents
* @see java.math.BigInteger
*/

public class BigMath
{
/**
* This method computes the non-negative power of a non-negative "BigInteger"
* for a given non-negative integer exponent using repeated multiplication;
* given a base, b, and the exponent n, the function uses n-1 multiplications
* to compute b * b * b * ..... * b, where b is used as a factor n times.
* @param base a non-negative object of the BigInt class
* @param n a non-negative integer
* @return the power of a big integer to the specified non-negative exponent
* @throw IllegalArgumentExcepiton when n is negative or base is not positive.
*/
public static BigInteger naivePow(BigInteger base, int n) throws IllegalArgumentException
{
//Implement this method
}

/**
* This method computes the non-negative power of a positive "BigInteger"
* using the fast power algorithm that uses successive squaring
* @param base a positive object of the BigInt class
* @param n a non-negative integer
* @return the power of a big integer to the specified non-negative exponent
* @throw IllegalArgumentException when n is negative or base is not positive.
*/
public static BigInteger fastPow(BigInteger base, int n) throws IllegalArgumentException
{
//Implement this method   
}
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution