Question
DO IT IN JAVA Primes The skeleton of the Primes class already exists and is in Primes.java. Step 1. Look at the skeleton in Primes.java.
DO IT IN JAVA
Primes The skeleton of the Primes class already exists and is in Primes.java.
Step 1. Look at the skeleton in Primes.java. Compile Primes. Run the main method in Primes. Checkpoint: If all has gone well, the program will run and accept input. It will then end. The goal now is to create the list of candidates.
Step 2. In main declare and create the candidates list. Add in the values.
Step 3. Print out the candidates list. Checkpoint: Compile and run the program. Enter 7 for the maximum value. You should see the list { }. The next goal is to do a single round finding a prime in the candidates list.
Step 4. In main declare and create the primes and composites lists. Step 5. Remove the first value from the primes list and remember it in a variable. Step 6. Print out the prime that was discovered.
Step 7. Add it to the primes list.
Step 8. Print out all three lists. Checkpoint: Compile and run the program. Enter 7 for the maximum value. The value 2 should be removed from the candidates list and added to the primes. Now all values that are divisible by the prime should be removed from the candidates list and added to the composites list. Next, this procedure will be encapsulated in the method getComposites().
Step 9. Refer to the pre-lab exercises and complete the getComposites() method. To determine if one integer value is divisible by another, you can use the modulus operator (% in Java).
Step 10. Between the code from steps 7 and 8, call getComposites(). Lab Manual for Data Structures and Abstractions with Java 171 Checkpoint: Compile and run the program. Enter 15 for the maximum value. Compare the results with the pre-lab exercises. Reconcile any differences. Just as in the counting game, a loop will be used to do the rounds.
Step 11. Wrap the code from steps 5 through 8 in a while loop that continues as long as the candidates list is not empty. Final checkpoint: Compile and run the program. Enter 15 for the maximum value. Compare the results with the pre-lab exercises. Reconcile any differences. Run the program with 100 as the maximum value. Carefully verify your results
import java.io.*;
import java.util.*;
/**
* Primes is a program that will compute prime numbers using the sieve of Eratosthenes.
*
* @author Charles Hoot
* @version 4.0
*/
public class Primes
{
public static void main(String args[])
{
int max;
System.out.println("Please enter the maximum value to test for primality");
max = getInt(" It should be an integer value greater than or equal to 2.");
// COMPLETE THE MAIN
}
/**
* getComposites - Remove the composite values from possibles list and
* put them in the composites list.
*
* @param candidates A list of integers holding the possible values.
* @param composites A list of integers holding the composite values.
* @param prime An Integer that is prime.
*/
public static void getComposites(ListInterface candidates, ListInterface composites, Integer prime)
{
// COMPLETE THIS METHOD
}
/**
* Get an integer value.
*
* @return An integer.
*/
private static int getInt(String rangePrompt)
{
Scanner input;
int result = 10; //Default value is 10
try
{
input = new Scanner(System.in);
System.out.println(rangePrompt);
result = input.nextInt();
}
catch(NumberFormatException e)
{
System.out.println("Could not convert input to an integer");
System.out.println(e.getMessage());
System.out.println("Will use 10 as the default value");
}
catch(Exception e)
{
System.out.println("There was an error with System.in");
System.out.println(e.getMessage());
System.out.println("Will use 10 as the default value");
}
return result;
}
}
-If need anything else just comment also I realize ihavent posted AList and Listerinterface because the questions is to long, but im not sure there any other way to send it to you cause i can't use a 3rd party website. Chegg gave me warning when i used a cite called codeshare to share my code. Not sure if im allowed to use google drive to share my code.
Imma share AList and Listinterface using google drive because an expert said that im allowed to use it, but not trusted :( Can you please me if im allowed to use google drive to share code because i dont want my accoun to get banned. Thank you. VERY IMMPORTANT I MUST KNOW.
https://docs.google.com/document/d/1yM-pOj313dAci10UrgAgEmnGZ1hqvqjeISO2Zz8QQBM/edit?usp=sharing
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