COP 2210 sections 5, 6 & 7

Assignment 2: Prime Factors

Due Date: February 27, at the beginning of the class. Late assignments will not be accepted.

The program must be completed in groups of two students. You can’t work with the same person you worked with for assignment 1. Your printout must names of both members of your teams. Teams of less or more than 2 students are not accepted.Turn in a printout of your program and sample output

A prime number is a number that is only divisible by 1 and the number itself. For example 5, 7, 11, 19 and 123 are prime numbers but 8 is not a prime number.

Write a program that reads a sequence of integer numbers (larger than 1)and displays the input numbers’ prime factors. The following are a few input/output examples:

Input / Output
12 / 2
2
3
15 / 3
5
28 / 2
2
7
5 / 5

Your program must contain the following methods

public static boolean isPrime(int m)

/

Accepts one integer parameter, m, and returns true, if m is a prime number. Otherwise, isPrime returns false.

For example, isPrime(72) returns false, whereas isPrime(11) returns true;

public static int nextPrime(int m)

/

Accepts one integer parameter, m and returns the first prime number that is larger than m.

For example nextPrime(6) will return 7 and nextPrime(27) returns 29

The main method must:

  1. Prompt the user for an input number with a meaningful message.
  2. If the input value is less than or equal to 1, the user must be informed of the error in the input, and then be prompted for another input
  3. If more than three consecutive erroneous input values are entered, the program must be terminated with an appropriate error message
  4. If the input is larger than 1, then its prime factors must be displayed
  5. After displaying the prime factors, the program must ask whether or not the user wants to enter another input (Do you want to continue? (y/n))
  6. The user must answer either yes, no, y or n using any combination of lower and upper case letters.
  7. If an invalid answer is given, the user must be informed that the answer was not acceptable, and then be prompted again for another answer.
  8. If more than three consecutive erroneous answers are given, the program must be terminated with an appropriate error message.
  9. If the answer in step 6, is Yes (in any allowed form) the program must continue from step 1.
  10. If the answer is No (in any allowed form) the program must terminate with a message informing that the program is terminated normally.
  11. All input must be done using an Scanner object i.e.

Scanner inp = new Scanner (System.in);

  1. All output should be done using System.out.