Question: Help with pseudocode only!!!! Write algorithms and programs to create a class PrimeSequence that ……

Help with pseudocode only!!!!

Write algorithms and programs to create a class PrimeSequence that implements the Sequence interface – refer to P10.2 on page 508 in the text – and the next() method. This problem utilizes the Worked Example 10.1 (page 473 in the text – go to wiley.com/go/javaexamples for sample downloads). 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.

Don't use plagiarized sources. Get Your Custom Essay on
Question: Help with pseudocode only!!!! Write algorithms and programs to create a class PrimeSequence that ……
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!

Output: Output will provide a table of n prime numbers. The table will be as close to b“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 digit’s entry (a sequence of *’s) must fit on a single row, and it must be properly labeled (actual count, scaled %). Scale will need to be flexible. Round up fraction percentages. All output should be handled by the Demo class. A sample output is provided below.

Input: Input will be provided on the command-line (see 11.3, pages 527-529 for details). Two input constants will be placed on the command-line upon execution. For example: java SequenceDemo 2 25 ; where the prime sequence will start with the next prime after the first number (3), and the second number (n) is the number of prime numbers to be sequenced (25). Both numbers will be integers and both numbers must be 1 or greater. Command-line input will need to be validated. If either input fails validation, your program should display why the input failed, and it should gracefully terminate, using System.exit(1). Instructions for compilation/execution should include command-line input details and requirements, and document that the Sequence interface needs to be in the same directory with your source code.

public class PrimeSequenceTester {

public static void main(String[] args) {

final int TARGET_NUMBER_OF_PRIMES = 100;
Sequence primes = new PrimeSequence();

System.out.println(“The first ” + TARGET_NUMBER_OF_PRIMES + ” prime numbers are as follows:n”);

for (int index = 1; index <= TARGET_NUMBER_OF_PRIMES; index++) {
// formats the output with each element in a field of length 4
System.out.printf(“%4d”, primes.next());
if (index % 10 == 0) {
System.out.println();
}
}

System.out.println();
}

}
—————————————————————————————-
public class PrimeSequence implements Sequence {

private int number = 1;

// Cycles through each number testing their prime status
@Override
public int next() {
boolean primeFlag = false;
while (!primeFlag) {
number++;
primeFlag = isPrime(number);
}
return number;
}

// Determines if a number is prime
public boolean isPrime(int number) {
boolean factorFlag = false;
int divisor = 2;
while (!factorFlag && divisor <= Math.sqrt(number)) {
if (number % divisor == 0) {
factorFlag = true;
}
divisor++;
}
return !factorFlag;
}

}
————————————————————————————
public interface Sequence {

// Finds the next element in a sequence.

int next();
}

Order NOW For a 10% Discount!
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.