Assignment 16 Points 60 Due Thursday November 102016700PM Ob

Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and methods . Get practice passing arrays to methods task of the method accurate method headers Print out the prime sexy prime triplets in a specific range in the speofied format and declaring local variables inside those methods that will assist in accomplishing the desred for each method and the example nain () method provided, determine how to write correct and Using the javadoc documentation for each method and the example main() method Introduction: In mathematics, a prime number (or a prime) is a natural number greater than one whose only positive divisors are one and itselt. A natural number that is greater than one and is not a prime is called a composite number The numbers zero and one are nesther prime nor composte 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/Prine number In mathematics, a sexy prime triplet are three (p. p 6, p 12) 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 prine. Some examples of sexy prime triplets are 5, 11, 17 and 7, 13, 19 For this program, you are first going to calculate t Eratosthenes and then display the sexy prime triplets within a range speafied by the user you are first going to calculate the prime numbers between 1 and 50000 using an algorithm known as the Sieve of Class and File Naming: NetID] sieve.java Grading Notes: Commit and push the complete, working. correctly-named source file within the homework drectory by the due date for ful credit Do not use any material beyond L20 (Up through and including Chapter 6 and parts of 19). Your program will not be graded if you do. .Program o 10 pts] Input/ output formatting [15 pts) Correct results o [15 pts] Correct use of methods o 15 pts] Well-named variables [message ] 16 pts] Commit 1st (10 com mits expected) . each shold be in the format P16 .

Solution

Program Code:

package sample;

import java.util.Scanner;

/**

* This class will use sieve of Erastothenes algorithm to find out the sexy primes

* The class also allows the user to input lower and upper boundaries

* @author: Kaju

* @version: 1

*/

public class NetID_Sieve {

  

   static boolean primeNumbers[] = new boolean[50001];

   /**

   * constructor for the class

   * Initializes the boolean array with true for all the indexes and false for 0th and 1st indexes

   */

   public NetID_Sieve()

   {

       primeNumbers[0] = false;

       primeNumbers[1] = false;

      

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

       {

           primeNumbers[i] = true;

       }

   }

  

   /**

   * This is the sieve algorithm that will find if the numbers between the boundaries are prime and then populate the

   * indexes in the array corresponding to the value for the number with appropriate value

   * i.e false - if the number is not prime

   * @param lowerBound - starting index for the array

   * @param UpperBound - end index for the array

   */

   public static void sieveOfErastothenesAlgorithm(int lowerBound, int UpperBound)

   {

       int i = 2, j=0;

       try{

           for( i=2; i<=UpperBound; i++)

           {

               /*if(i<46341)

                   j = i*i;

               else

                   continue;*/

               int prime = (int) Math.ceil(Math.sqrt(i));

      while (prime > 1)

      {

      if ((i != prime) && (i % prime == 0))

      {

      primeNumbers[i] = false;

      break;

      }

      --prime;

      }

           }

       }catch (Exception e) {

           System.out.println(i + \"\" + j);

       }

      

   }

  

   /**

   * This is the function that would display the prime numbers as triplets.

   * Also prints the count of triplets

   * @param lowerbound

   * @param upperbound

   */

   public static void display(int lowerbound, int upperbound)

   {

  

       int counter = 0;

       for(int i=lowerbound; i<=upperbound-12; i++)

       {

           if(primeNumbers[i] == true && primeNumbers[i+6] == true && primeNumbers[i+12] == true)

           {

               System.out.println(i + \" and \" + (i+6) + \" and \" + (i+12));

               counter++;

           }

       }

       System.out.println(\"There were \" + counter + \" sexy prime triplets displayed\");

   }

  

   /**

   * Trigger point for the class.

   * This function first calls the algorithm with lowerbound - 1 and upperbound - 50000 and displays the triplets

   * After that it will prompt the user to enter the lowerbound and upperbound and then finds the primenumbers.

   * finally prints the array

   * @param args

   */

   public static void main(String[] args) {

       new NetID_Sieve();

       System.out.println(\"Here are all the sexy prime triplets in the range 1 to 50000, one set of triplets per line\");

       sieveOfErastothenesAlgorithm(1, 50000);

       display(1, 50000);

       int lowerboundry = 0, upperboundary = 0;

       Scanner intscanner = new Scanner(System.in);

       while(lowerboundry<=0 || lowerboundry>50000)

       {

           System.out.println(\"Enter the lower boundary (between 1 and 50000) : \");

           lowerboundry = intscanner.nextInt();

       }

       while(upperboundary<=lowerboundry || upperboundary>50000)

       {

           System.out.println(\"Enter the upper boundary (between \"+ lowerboundry+ \" and 50000) : \");

           upperboundary = intscanner.nextInt();

       }

       intscanner.close();

       sieveOfErastothenesAlgorithm(lowerboundry, upperboundary);

       display(lowerboundry, upperboundary);

   }

}

OUTPUT:

Here are all the sexy prime triplets in the range 1 to 50000, one set of triplets per line

5 and 11 and 17

7 and 13 and 19

11 and 17 and 23

17 and 23 and 29

31 and 37 and 43

41 and 47 and 53

47 and 53 and 59

61 and 67 and 73

67 and 73 and 79

97 and 103 and 109

101 and 107 and 113

151 and 157 and 163

167 and 173 and 179

227 and 233 and 239

251 and 257 and 263

257 and 263 and 269

271 and 277 and 283

347 and 353 and 359

367 and 373 and 379

557 and 563 and 569

587 and 593 and 599

601 and 607 and 613

607 and 613 and 619

641 and 647 and 653

647 and 653 and 659

727 and 733 and 739

941 and 947 and 953

971 and 977 and 983

1091 and 1097 and 1103

1097 and 1103 and 1109

1117 and 1123 and 1129

1181 and 1187 and 1193

1217 and 1223 and 1229

1277 and 1283 and 1289

1291 and 1297 and 1303

1361 and 1367 and 1373

1427 and 1433 and 1439

1447 and 1453 and 1459

1481 and 1487 and 1493

1487 and 1493 and 1499

1601 and 1607 and 1613

1607 and 1613 and 1619

1657 and 1663 and 1669

1741 and 1747 and 1753

1747 and 1753 and 1759

1777 and 1783 and 1789

1861 and 1867 and 1873

1867 and 1873 and 1879

1901 and 1907 and 1913

1987 and 1993 and 1999

2131 and 2137 and 2143

2281 and 2287 and 2293

2371 and 2377 and 2383

2377 and 2383 and 2389

2411 and 2417 and 2423

2671 and 2677 and 2683

2677 and 2683 and 2689

2687 and 2693 and 2699

2707 and 2713 and 2719

2791 and 2797 and 2803

2897 and 2903 and 2909

2957 and 2963 and 2969

3301 and 3307 and 3313

3307 and 3313 and 3319

3457 and 3463 and 3469

3527 and 3533 and 3539

3631 and 3637 and 3643

3727 and 3733 and 3739

3911 and 3917 and 3923

3917 and 3923 and 3929

4001 and 4007 and 4013

4007 and 4013 and 4019

4127 and 4133 and 4139

4451 and 4457 and 4463

4507 and 4513 and 4519

4591 and 4597 and 4603

4637 and 4643 and 4649

4651 and 4657 and 4663

4787 and 4793 and 4799

4931 and 4937 and 4943

4987 and 4993 and 4999

5101 and 5107 and 5113

5107 and 5113 and 5119

5297 and 5303 and 5309

5381 and 5387 and 5393

5387 and 5393 and 5399

5407 and 5413 and 5419

5431 and 5437 and 5443

5437 and 5443 and 5449

5471 and 5477 and 5483

5557 and 5563 and 5569

5641 and 5647 and 5653

5647 and 5653 and 5659

5737 and 5743 and 5749

5801 and 5807 and 5813

6067 and 6073 and 6079

6257 and 6263 and 6269

6311 and 6317 and 6323

6317 and 6323 and 6329

6361 and 6367 and 6373

6367 and 6373 and 6379

6857 and 6863 and 6869

6971 and 6977 and 6983

7207 and 7213 and 7219

7517 and 7523 and 7529

7577 and 7583 and 7589

7817 and 7823 and 7829

7867 and 7873 and 7879

8081 and 8087 and 8093

8111 and 8117 and 8123

8231 and 8237 and 8243

8707 and 8713 and 8719

8741 and 8747 and 8753

9001 and 9007 and 9013

9337 and 9343 and 9349

9391 and 9397 and 9403

9461 and 9467 and 9473

9467 and 9473 and 9479

10247 and 10253 and 10259

10331 and 10337 and 10343

10601 and 10607 and 10613

10651 and 10657 and 10663

10847 and 10853 and 10859

11491 and 11497 and 11503

11777 and 11783 and 11789

11801 and 11807 and 11813

11821 and 11827 and 11833

11827 and 11833 and 11839

11897 and 11903 and 11909

11927 and 11933 and 11939

12037 and 12043 and 12049

12101 and 12107 and 12113

12107 and 12113 and 12119

12491 and 12497 and 12503

12541 and 12547 and 12553

12577 and 12583 and 12589

12641 and 12647 and 12653

12647 and 12653 and 12659

12911 and 12917 and 12923

12967 and 12973 and 12979

13037 and 13043 and 13049

13171 and 13177 and 13183

13451 and 13457 and 13463

13457 and 13463 and 13469

13681 and 13687 and 13693

13751 and 13757 and 13763

13901 and 13907 and 13913

14537 and 14543 and 14549

14551 and 14557 and 14563

14621 and 14627 and 14633

14627 and 14633 and 14639

14741 and 14747 and 14753

14747 and 14753 and 14759

15187 and 15193 and 15199

15307 and 15313 and 15319

15461 and 15467 and 15473

15727 and 15733 and 15739

15761 and 15767 and 15773

15791 and 15797 and 15803

15797 and 15803 and 15809

15901 and 15907 and 15913

15907 and 15913 and 15919

16057 and 16063 and 16069

16061 and 16067 and 16073

16091 and 16097 and 16103

16217 and 16223 and 16229

16421 and 16427 and 16433

16481 and 16487 and 16493

16561 and 16567 and 16573

16931 and 16937 and 16943

16981 and 16987 and 16993

17021 and 17027 and 17033

17041 and 17047 and 17053

17321 and 17327 and 17333

17377 and 17383 and 17389

17471 and 17477 and 17483

17477 and 17483 and 17489

18121 and 18127 and 18133

18211 and 18217 and 18223

18217 and 18223 and 18229

18301 and 18307 and 18313

18427 and 18433 and 18439

19207 and 19213 and 19219

19417 and 19423 and 19429

19421 and 19427 and 19433

19457 and 19463 and 19469

19471 and 19477 and 19483

19477 and 19483 and 19489

19571 and 19577 and 19583

19597 and 19603 and 19609

20101 and 20107 and 20113

20117 and 20123 and 20129

20341 and 20347 and 20353

20347 and 20353 and 20359

20747 and 20753 and 20759

21011 and 21017 and 21023

21157 and 21163 and 21169

21481 and 21487 and 21493

21487 and 21493 and 21499

21517 and 21523 and 21529

21557 and 21563 and 21569

21991 and 21997 and 22003

22067 and 22073 and 22079

22147 and 22153 and 22159

22271 and 22277 and 22283

22441 and 22447 and 22453

23197 and 23203 and 23209

23321 and 23327 and 23333

23327 and 23333 and 23339

23741 and 23747 and 23753

23761 and 23767 and 23773

23887 and 23893 and 23899

24071 and 24077 and 24083

24091 and 24097 and 24103

24097 and 24103 and 24109

24407 and 24413 and 24419

24671 and 24677 and 24683

25457 and 25463 and 25469

25577 and 25583 and 25589

25667 and 25673 and 25679

26107 and 26113 and 26119

26171 and 26177 and 26183

26177 and 26183 and 26189

26387 and 26393 and 26399

26681 and 26687 and 26693

26687 and 26693 and 26699

26711 and 26717 and 26723

26717 and 26723 and 26729

26947 and 26953 and 26959

26981 and 26987 and 26993

27061 and 27067 and 27073

27271 and 27277 and 27283

27737 and 27743 and 27749

27767 and 27773 and 27779

27941 and 27947 and 27953

28277 and 28283 and 28289

28591 and 28597 and 28603

28657 and 28663 and 28669

28921 and 28927 and 28933

29021 and 29027 and 29033

29167 and 29173 and 29179

29327 and 29333 and 29339

29867 and 29873 and 29879

30091 and 30097 and 30103

30097 and 30103 and 30109

30307 and 30313 and 30319

30631 and 30637 and 30643

30637 and 30643 and 30649

30971 and 30977 and 30983

31147 and 31153 and 31159

31177 and 31183 and 31189

31247 and 31253 and 31259

31321 and 31327 and 31333

32051 and 32057 and 32063

32057 and 32063 and 32069

32077 and 32083 and 32089

32297 and 32303 and 32309

32491 and 32497 and 32503

32707 and 32713 and 32719

32987 and 32993 and 32999

33107 and 33113 and 33119

33347 and 33353 and 33359

33617 and 33623 and 33629

33851 and 33857 and 33863

34261 and 34267 and 34273

34537 and 34543 and 34549

34667 and 34673 and 34679

34871 and 34877 and 34883

35311 and 35317 and 35323

35521 and 35527 and 35533

35531 and 35537 and 35543

35591 and 35597 and 35603

35747 and 35753 and 35759

35797 and 35803 and 35809

36061 and 36067 and 36073

36307 and 36313 and 36319

36467 and 36473 and 36479

36671 and 36677 and 36683

36781 and 36787 and 36793

37357 and 37363 and 37369

37561 and 37567 and 37573

37567 and 37573 and 37579

37951 and 37957 and 37963

38177 and 38183 and 38189

38321 and 38327 and 38333

38447 and 38453 and 38459

38861 and 38867 and 38873

39107 and 39113 and 39119

39227 and 39233 and 39239

39857 and 39863 and 39869

40087 and 40093 and 40099

40277 and 40283 and 40289

40487 and 40493 and 40499

40841 and 40847 and 40853

40927 and 40933 and 40939

41011 and 41017 and 41023

41177 and 41183 and 41189

41221 and 41227 and 41233

41257 and 41263 and 41269

41507 and 41513 and 41519

41597 and 41603 and 41609

41941 and 41947 and 41953

41947 and 41953 and 41959

42181 and 42187 and 42193

42391 and 42397 and 42403

42397 and 42403 and 42409

42451 and 42457 and 42463

42461 and 42467 and 42473

42677 and 42683 and 42689

42697 and 42703 and 42709

43391 and 43397 and 43403

43777 and 43783 and 43789

43781 and 43787 and 43793

44257 and 44263 and 44269

44267 and 44273 and 44279

44531 and 44537 and 44543

44537 and 44543 and 44549

45427 and 45433 and 45439

45491 and 45497 and 45503

45751 and 45757 and 45763

45821 and 45827 and 45833

46141 and 46147 and 46153

47137 and 47143 and 47149

47297 and 47303 and 47309

47501 and 47507 and 47513

47521 and 47527 and 47533

48017 and 48023 and 48029

48527 and 48533 and 48539

49031 and 49037 and 49043

49627 and 49633 and 49639

There were 330 sexy prime triplets displayed

Enter the lower boundary (between 1 and 50000) :

0

Enter the lower boundary (between 1 and 50000) :

50002

Enter the lower boundary (between 1 and 50000) :

150

Enter the upper boundary (between 150 and 50000) :

100

Enter the upper boundary (between 150 and 50000) :

200

151 and 157 and 163

167 and 173 and 179

There were 2 sexy prime triplets displayed

 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method
 Assignment: 16 Points: 60 Due: Thursday, November. 10,2016@7:00PM Objectives: Write a moderately difficult program that uses a one-dimensional array and method

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site