Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write algorithms and programs to create a class PrimeSequence that implements the Sequence interface / the next() method. Provide a Demo program that will produce

Write algorithms and programs to create a class PrimeSequence that implements the Sequence interface / the next() method. Provide a Demo program that will produce an arbitrary sequence of n prime numbers in table format and will perform an analysis of those n prime numbers.

Output will provide a table of n prime numbers. The table will be as close to square as possible - i.e. same number of rows and columns - with at most 10 entries per row. All entries will be right-aligned. Additionally, output will include a histogram of the occurrences of the last digit [0-9] of each prime number. The histogram will be horizontal (not vertical) and will be scaled (as a percentage %), with a legend at the bottom to explain the scale and display the total count of primes. Each digits entry (a sequence of *s) must fit on a single row, and it must be properly labeled (actual count, scaled %). All output should be handled by the Demo class. A sample output is provided below.

Printing a sequence of 25 prime numbers:

3 5 7 11 13

17 19 23 29 31

37 41 43 47 53

59 61 67 71 73

79 83 89 97 101

Last Digit Histogram:

[0] (0, 0%)

[1]************************ (6, 24%)

[2] (0, 0%)

[3]**************************** (7, 28%)

[4] (0, 0%)

[5]**** (1, 4%)

[6] (0, 0%)

[7]************************ (6, 24%)

[8] (0, 0%)

[9]******************** (5, 20%)

__________________________________

Total(actual count, %) (25, 100%)

Scaled as %, * = 1%

You will use the Sequence interface [containing the next() method] as defined in Worked Example 10.1. You must write at least two programs: one will be the PrimeSequence class that will implement the interface; and one will be the SequenceDemo class that will perform the demonstration/analysis. Document use of external sources, including the text, as required.

The PrimeSequence class will implement the next() method, an isPrime() method to determine if a number is prime, and any other methods/instance variables required for the class. Note: the first prime number is 2.

The SequenceDemo class will accept and validate the command-line input, and starting where specified, request the specified number (n) of primes, collecting data for analysis, and preparing the table and histogram for output. The analysis will entail counting how many instances of each digit [0-9] occur on the last digit of each prime. You may be required to search for (or implement) your own Boolean isInteger() method, for validation.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

7. Senior management supports the career system.

Answered: 1 week ago