Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m in java one and need help with this code. please follow the directions give

ID: 3682877 • Letter: I

Question

I'm in java one and need help with this code. please follow the directions given and test your program to make sure it works as it is required. I will apreciate your help. thank you.

?Goals

^ Write a moderately difficult program that uses a one-dimensional array and methods.

?^ Get practice passing arrays to methods and declaring local variables inside those methods that will assist in accomplishing the desired task of the method.

?^ Using the javadoc documentation for each method and the example main() method provided, determine how to write correct and accurate method headers.

?^ Print out the prime sexy prime pairs in a specific range in the specified format.

Points to Think About

?^ The processSieve() method doesn’t need to do any input or output.

^? The getLower() and getUpper() methods, by their nature, will need to do both input and output. You will need to create Scanner objects ineach method.

?^ The showPrimes() method should only display the sexy prime pairs between the lower and upper boundaries.

?^ Do not alter the implementation of the main() method in any significant way. This will assist you in creating your method headers correctly

OVERVIEW OF PRIME NUMBERS In mathematics, a prime number (or a prime) is a natural number greater than one who's only positive divisors are one and itself. A natural number that is greater than one and is not a prime is called a composite number. The numbers zero and one are neither prime nor composite. The property of being a prime is called primality. Since 2 is the only even prime number, the term odd prime refers to all prime numbers greater than 2. - Definition taken from http://en.wikipedia.org/wiki/Prime_number In mathematics, a sexy prime is a pair (p, p 6) of prime numbers that differ by six. The name "sexy prime" stems from the Latin word for six: sex. Definition taken from http://en.wikipedia.org/wiki/Sexy prime - Some examples of sexy prime pairs are 5 and 11, 7 and 13, and 461 and 467 For this program, you are first going to calculate the prime numbers between 1 and 50000 using an algorithm known as the Sieve of Eratosthenes and then display the sexy prime pairs within a range specified by the user. TEMPLATE TO START YOUR PROGRAM: NetIDSieve.iava To get you started for this assignment, you will be given a main () method. You will need to type this in as you see it here, without modifications other than to put in your on Net ID and leave out the comments if you don't want to type them in. For this assignment, you will be creating the supporting methods in addition to main). The discussion of each of the supporting methods is described on the following pages.

Explanation / Answer

import java.util.Scanner;

import java.io.*;

public class NetID_Sieve

{

Scanner in = new Scanner(System.in);

boolean primes [] = new boolean [50001];

int upper;

int lower;

public NetID_Sieve()

{

primes[0] = false;

primes[1] = false;

for (int i = 2; i < primes.length; i++)

{

primes[i] = true;

}

getLower();

getUpper();

processSieve();

showPrimes();

}

public void processSieve()

{

for (int i =2; (i * i) <= upper; i++)

{

for (int j = (i * i); j <= upper; j = j + i)

{

primes[j] = false;

}

}

}

public void getLower()

{

int y=0;

do

{

System.out.println("Please enter a lower boundary ( 1 - 50000): ");

lower= in.nextInt();

if (( lower < 1) || (lower> 50000))

{

System.out.println("Please enter a valid number");

y = 1;

}

if (( lower > 1) || (lower< 50000))

{

y = 0;

}

}

while ( y== 1);

}

public void getUpper()

{

int y=0;

do

{

System.out.println("Please enter a upper boundary ( 1 - 50000): ");

upper = in.nextInt();

if (( upper < 1) || (upper> 50000))

{

System.out.println("Please enter a valid number");

y = 1;

}

if (( upper> 1) || (upper< 50000))

{

y = 0;

}

}

while ( y == 1);

}

public void showPrimes()

{

for (int i = 2; i < upper; i++)

{

if (primes[i] == true)

{

System.out.println( i + " is prime");

}

}

}

public static void main (String args[])

{

NetID_Sieve l = new NetID_Sieve();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote