Question: In JAVA Please. These are the directions First we ll create a class called Prime. If you are a java student import java.util.LinkedList, then create

In JAVA Please. These are the directionsFirst well create a class called Prime. If you are a java student import java.util.LinkedList, then create a linked list of Integers. If you are a C# student, using System, System.Collections.Generic and Systems.Linq, then make a LinkedList of int. Write a constructor which takes in an integer called max and calculates all primes up to max. Start off with an array of booleans of the max size. Initialize all cells to true You are going to use this array of booleans to find the prime numbers. The index of the cell in the array represents the number you are deciding if its prime or not. A true value in the cell indicates that index is prime, a false value indicates its not. Follow the algorithm described above. Youll ignore cells 0 and 1 of the array, because those arent prime numbers. Using a loop, start at 2, and continue until you reach the square root of max Change the value of each cell to false when you determine its not a prime. Once youve completed the algorithm all cells still true are prime. Add all prime numbers to the linked list: Java students, can use .add() C# students can use .AddFirst() Write a method isPrime which takes in a number and returns true if its found anywhere in the LinkedList. Using a foreach loop, iterate over the LinkedList. If the number passed in is found in the list, return true, otherwise false. Write a method getPrime which takes a position in the linked list and returns that value. For example, if passed 0 it should return 2(the first prime), if passed 1 it would return 3(the next prime), if passed 2 it would return 5(the 3rd prime)... Note: Java students can use .get() on a linked list. C# students will need .ElementAt(). ElementAt requires that you are using System.Linq Next in your Main class: Create a constant and set it to 10000 Write a method findFactor which takes in a target (int) and a Prime object. Use a loop starting at index 0 of the linked list and going up to the target. Find the first prime number (using getPrime() in the Prime object) that evenly divides into the target. Return that number. For example, if passed 10, it would return 2, since 2 is the first prime number that divides into 10 evenly. If passed 9, it would return 3 since 2 doesnt divide evenly, but 3 does. If passed 25, itll return 5. If you cant find a value, return -1(this would only happen if the method were passed a number 2. Print out What primes make up followed by the number you picked. Using a loop: Call findFactor on the target number, which will return the lowest prime factor. Print that factor (followed by a plus, unless its the last factor) Divide the target by the returned factor Repeat calling findFactor on the smaller values until you are left with a number less than 2.Sample Output:[NOTE: Each time it is run, youll get a different random output][First Run]What primes make up 7976?997x2x2x2[Second Run]What primes make up 6638?3319x2[Third Run]What primes make up 2860?13x11x5x2x2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!