Usetutoringspotscode to get 8% OFF on your first order!

  • time icon24/7 online - support@tutoringspots.com
  • phone icon1-316-444-1378 or 44-141-628-6690
  • login iconLogin

CS/INFO 1181

CS/INFO 1181
Project 4 – Perfect numbers
due Feb 9, 11:00 pm
Project Instructions
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.
Strategy
1. Create a project called Perfect.
2. Add a heading at the top of your file as follows:
1
/*
* 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.
Style
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.
Scoring
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).
Submission
Upload the source file Perfect.java to Moodle under “Project 4”.
2

You can leave a response, or trackback from your own site.

Leave a Reply

CS/INFO 1181

CS/INFO 1181
Project 4 – Perfect numbers
due Feb 9, 11:00 pm
Project Instructions
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.
Strategy
1. Create a project called Perfect.
2. Add a heading at the top of your file as follows:
1
/*
* 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.
Style
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.
Scoring
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).
Submission
Upload the source file Perfect.java to Moodle under “Project 4”.
2

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

CS/INFO 1181

CS/INFO 1181
Project 4 – Perfect numbers
due Feb 9, 11:00 pm
Project Instructions
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.
Strategy
1. Create a project called Perfect.
2. Add a heading at the top of your file as follows:
1
/*
* 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.
Style
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.
Scoring
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).
Submission
Upload the source file Perfect.java to Moodle under “Project 4”.
2

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes