CSE 1020 - Sample labtest

Phase 1

Present the user with the following prompt.
Enter a positive integer:
The entry has to be made on the same line as the prompt.

Here is a sample run (including the integer entered by the user):

Enter a positive integer: 8

Phase 2

Next, expand your program to read the entered integer. You may assume that the reader always enters an integer. (This a precondition of your app.)

Phase 3

Assume that the entered integer is i. Next, expand your program to create i random Person objects and print them (that is, print their names). The API of the Person class can be found here.

Here is a sample run (including the output and input of the earlier phases as well):

Enter a positive integer: 8
Peter Daniels
Paul Star
Ringo Cribb
Ringo Cribb
Ringo McCarty
Paul Cribb
Peter Daniels
Ringo Lennon

Phase 4

Next, expand your program so that also the average age of the created persons is computed.

Phase 5

Next, expand your program so that is also prints the string The average age is followed by the computed average age. The average age should be given with two digits precision.

Here is a sample run (including the output and input of the earlier phases as well):

Enter a positive integer: 8
Peter Daniels
Paul Star
Ringo Cribb
Ringo Cribb
Ringo McCarty
Paul Cribb
Peter Daniels
Ringo Lennon
The average age is 44.32

Phase 6

Finally, modify your program such that the user is reprompted if the user enters an integer that is not greater than zero.

Here is a sample run (including the output and input of the earlier phases as well):

Enter a positive integer: -2
Enter a positive integer: 0
Enter a positive integer: 8
Peter Daniels
Paul Star
Ringo Cribb
Ringo Cribb
Ringo McCarty
Paul Cribb
Peter Daniels
Ringo Lennon
The average age is 44.32