Project 4 – Perfect numbers
due Feb 9, 11:00 pm
A perfect number is a positive integer that is equal to the sum of its proper divisors. For example,
take the number 6. Its proper divisors, or numbers that divide evenly into it except for the number
itself, are 1, 2, and 3. Sum these numbers together and you get 6.
Another example is 28. Its proper divisors are 1, 2, 4, 7, and 14. The sum of these numbers is 28.
In this project, you will create a Java application that prompts the user for a number and then prints
out whether the number is perfect or not. In addition, if the user enters a negative number, you
should print an error message and re-prompt for a number. It should behave as follows (user input
is in bold):
Please enter a positive integer: -1
-1 is not positive.
Please enter a positive integer: -58
-58 is not positive.
Please enter a positive integer: 0
0 is not positive.
Please enter a positive integer: 6
6 is a perfect number.
Please enter a positive integer: 7
7 is not a perfect number.
Please enter a positive integer: 28
28 is a perfect number.
1. Create a project called Perfect.
2. Add a heading at the top of your file as follows:
* Name: Jack Black
* ID: blacjack
* Project 4
* Course: CS 1181
* Instructor: [Instructor name]
3. Add print(), println() and nextInt() statements for the input and output.
4. Make a loop that continues to prompt the user until the user enters a valid number.
5. Make a loop that looks at each value from 1 to number-1. Test each value to see if it is a
divisor of number. If it is, add it to the sum.
6. See if the sum is equal to the number. Print the correct output message.
7. Test. You can test using the first four perfect numbers: 6, 28, 496, and 8128.
Your code should be correctly formatted and have meaningful variables and comments. A note on
whitespace: it is very helpful to leave blank lines in your code judiciously. For example, it might
be helpful to leave a blank line between the loop that gets a valid value from the user and the loop
that sums the divisors.
1. 5% – Correct header with name, etc.
2. 10% – Compiles without errors.
3. 35% – Correctly gets a valid number, including error checking.
4. 40% – Correctly computes whether the number is perfect and outputs the result.
5. 10% – Correct code formatting (indentation, braces, whitespace, etc).
Upload the source file Perfect.java to Moodle under “Project 4”.
Is this question part of your Assignment?
We can help
Our aim is to help you get A+ grades on your Coursework.
We handle assignments in a multiplicity of subject areas including Admission Essays, General Essays, Case Studies, Coursework, Dissertations, Editing, Research Papers, and Research proposalsHeader Button Label: Get Started NowGet Started Header Button Label: View writing samplesView writing samples