-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerfectNumbers.java
More file actions
39 lines (33 loc) · 931 Bytes
/
Copy pathPerfectNumbers.java
File metadata and controls
39 lines (33 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class NaturalNumber {
public String outcome = "";
NaturalNumber(int number) {
int Result = 0;
if (number <= 0){
throw new IllegalArgumentException("You must supply a natural number (positive integer)");
}
for (int i = 1; i < number; i++){
if (number % i == 0){
Result += i;
}
}
if (Result > number){
outcome = "abundant";
}
if (Result < number){
outcome = "deficient";
}
if (Result == number){
outcome = "perfect";
}
}
Classification getClassification() {
if (outcome == "abundant"){
return Classification.ABUNDANT;
}
else if (outcome == "perfect"){
return Classification.PERFECT;
}
else
return Classification.DEFICIENT;
}
}