Question
Write a program in Java for computing abundant , deficient , perfect and prime numbers according to the following specifications: The program first asks the
Write a program in Java for computing abundant, deficient, perfect and prime numbers according to the following specifications:
The program first asks the user for an input in the form: condition = value, where condition is a word from the set {limit, deficient, abundant, perfect, prime}, and value is a positive integer.
Then it verifies the input. If the input is invalid it prints a message indicating that and terminates.
If the input is valid it prints a table with the number of abundant, deficient, perfect and prime numbers less than or equal to N, where N = 1, 2, 3, ..., limit.
The value of limit is determined by the user input. That is, the tabulation stops when the number in the corrsponding column reaches the value, specified in the input condition = value.
For example, if the user enters limit = 10 the progam should print:
N Abundand Deficient Perfect Prime
1 0 1 0 0
2 0 2 0 1
3 0 3 0 2
4 0 4 0 2
5 0 5 0 3
6 0 5 1 3
7 0 6 1 4
8 0 7 1 4
9 0 8 1 4
10 0 9 1 4
If the user enters abundant = 2 the progam should print:
N Abundand Deficient Perfect Prime
1 0 1 0 0
2 0 2 0 1
3 0 3 0 2
4 0 4 0 2
5 0 5 0 3
6 0 5 1 3
7 0 6 1 4
8 0 7 1 4
9 0 8 1 4
10 0 9 1 4
11 0 10 1 5
12 1 10 1 5
13 1 11 1 6
14 1 12 1 6
15 1 13 1 6
16 1 14 1 6
17 1 15 1 7
18 2 15 1 7
Requirements and restrictions:
Use the scanner class for input.
Use the Type class (Type.java) to check for the type of the value in the input.
Use proper names for the variables suggesting their purpose.
Format your code accordingly using indentation and spacing.
Use multiple line comment in the beginning of the code and write your name, e-mail address, class, and section.
For each line of code add a short comment to explain its meaning.
Extra credit (up to 2 points): After (or on the right of) the table the program should print a horizontal bar diagram with the numbers in the corresponding column specified in the input. Use star characters (*) to print the diagram
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started