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.180 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.179 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.178 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.177 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.176 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.175 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.174 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.173 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.172 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.171 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.170 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.169 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.167 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.166 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.165 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.164 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.163 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.162 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.161 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java
trackler-2.2.1.160 tracks/java/exercises/perfect-numbers/.meta/src/reference/java/NaturalNumber.java