Sha256: 3b81c893bb19ac52602023e7a9174f987a8333c52b52f167ca87f411cd2193c2

Contents?: true

Size: 843 Bytes

Versions: 284

Compression:

Stored size: 843 Bytes

Contents

import java.util.stream.IntStream;

final class NaturalNumber {

    private final int naturalNumber;

    NaturalNumber(int naturalNumber) {
        if (naturalNumber <= 0) throw new IllegalArgumentException("You must supply a natural number (positive integer)");
        this.naturalNumber = naturalNumber;
    }

    Classification getClassification() {
        final int aliquotSum = computeAliquotSum();

        if (aliquotSum == naturalNumber) {
            return Classification.PERFECT;
        } else if (aliquotSum > naturalNumber) {
            return Classification.ABUNDANT;
        } else {
            return Classification.DEFICIENT;
        }
    }

    private int computeAliquotSum() {
        return IntStream.range(1, naturalNumber)
                .filter(it -> naturalNumber % it == 0)
                .sum();
    }

}

Version data entries

284 entries across 284 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.138 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.137 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.136 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.135 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.134 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.133 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.132 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.131 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.130 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.129 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.128 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.127 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.126 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.125 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.124 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.123 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.122 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.121 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.120 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java