Skip to content

Instantly share code, notes, and snippets.

@sudhcha
Last active December 16, 2015 02:09
package org.sxvarg2.enums;
public abstract class LoanType implements Enumerable {
public static final LoanType HOME = new LoanType(7, 20) {
public boolean isEligible(int age, int creditScore) {
return age < 30 && creditScore > 700;
}
};
public static final LoanType CAR = new LoanType(5, 5) {
public boolean isEligible(int age, int creditScore) {
return age < 50 && creditScore > 700;
}
};
public static final LoanType EDUCATION = new LoanType(2, 20) {
public boolean isEligible(int age, int creditScore) {
return age < 25 && creditScore > 630;
}
};
public static final LoanType STARTUP = new LoanType(9, 5) {
public boolean isEligible(int age, int creditScore) {
return age < 40 && creditScore > 770;
}
};
private static final Object[] registeredTypes = new Object[] {HOME, CAR, EDUCATION, STARTUP };
private final int interestPercentage;
private final int maxRepayPeriod;
public int getInterestPercentage() {
return interestPercentage;
}
public int getMaxRepayPeriod() {
return maxRepayPeriod;
}
private LoanType(final int interestPercentage, final intmaxRepayPeriod) {
this.interestPercentage = interestPercentage;
this.maxRepayPeriod = maxRepayPeriod;
}
public final Object[] values() {
return registeredTypes;
}
public abstract boolean isEligible(int age, int creditScore);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment