Question
. 5. Write a program that computes the prime factorization of a positive integer number. The number in question is computed as the product of
. 5. Write a program that computes the prime factorization of a positive integer number. The number in question is computed as the product of prime numbers raised to various exponents. The prime factorization problem is finding the primes and their exponents. For instance, number 72 is the product 72 = 2^3*3^2 and 60 = 2^2*3*5, where ^ is the power (exponentiation) operator; ^ has higher precedence than multiplication. Write a class PrimeFactorizer with the following skeleton structure: public class PrimeFactorizer { /** * Initialize the object with target number n. */ public PrimeFactorizer(int n) { ... } /** * Return n, the target number. */ public int getN() { ... } /** * Compute factorization. Do not repeat operation if it was called before. */ public void compute() { ... } /** * Return the factors and exponents in two arraylists. * Call compute() first, if necessary. * For instance, if n=60, primes=[2,3,5], and exponents=[2,1,1]. */ public void getFactorsAndExponents(int n, ArrayList primes, ArrayList exponents) { .... } /** * Return a string with the "pretty" representation of the prime factorization. * For instance, if n is 60, then toString() for the PrimeFactorizer(60) object * should be "60 = 2^2*3*5". Call compute() if not done before. */ public String toString() { .... } ...... // other code, helper functions, etc. } Write a test class PrimeFactorTest with a main() function that reads an int number n from the terminal with the Scanner object, computes its prime factorization with a PrimeFactorizer object, and then displays the factorization to the terminal with System.out.println().
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started