idk ive done too much
This commit is contained in:
15
LAB-6/.classpath
Normal file
15
LAB-6/.classpath
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
LAB-6/.project
Normal file
17
LAB-6/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>LAB-6</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
7
LAB-6/src/module-info.java
Normal file
7
LAB-6/src/module-info.java
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @author brett
|
||||
*
|
||||
*/
|
||||
module uwstout.courses.cs144 {
|
||||
requires junit;
|
||||
}
|
||||
197
LAB-6/src/uwstout/courses/cs144/labs/lab6/LoanInfo.java
Normal file
197
LAB-6/src/uwstout/courses/cs144/labs/lab6/LoanInfo.java
Normal file
@@ -0,0 +1,197 @@
|
||||
package uwstout.courses.cs144.labs.lab6;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* Represents information for a possible loan, specifically the credit score,
|
||||
* desired amount, and number of years.
|
||||
*
|
||||
* @author Brett Bender
|
||||
* @version 2022.11.08
|
||||
*/
|
||||
public class LoanInfo {
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
// Initialization
|
||||
private static final int MIN_VALID_CREDIT_SCORE = 300;
|
||||
private static final int MAX_VALID_CREDIT_SCORE = 850;
|
||||
private static final double MIN_LOAN_AMOUNT = 10000.00;
|
||||
private static final int MIN_LOAN_YEARS = 5;
|
||||
|
||||
// Borders
|
||||
/// Anything 300-579 is poor
|
||||
private static final String POOR_CREDIT_STRING = "Poor";
|
||||
|
||||
/// Anything 580-669 is fair
|
||||
private static final int FAIR_CREDIT_BOUNDARY = 580;
|
||||
private static final String FAIR_CREDIT_STRING = "Fair";
|
||||
|
||||
/// Anything 670-739 is good
|
||||
private static final int GOOD_CREDIT_BOUNDARY = 670;
|
||||
private static final String GOOD_CREDIT_STRING = "Good";
|
||||
|
||||
/// Anything 740-799 is very good
|
||||
private static final int VGOOD_CREDIT_BOUNDARY = 740;
|
||||
private static final String VGOOD_CREDIT_STRING = "Very Good";
|
||||
|
||||
/// Anything 800-850 is exceptional
|
||||
private static final int EXCEPTIONAL_CREDIT_BOUNDARY = 800;
|
||||
private static final String EXCEPTIONAL_CREDIT_STRING = "Exceptional";
|
||||
|
||||
// Approval Values
|
||||
private static final int INSTANT_APPROVAL_CREDIT_SCORE = GOOD_CREDIT_BOUNDARY;
|
||||
private static final int MIN_APPROVAL_CREDIT_SCORE = FAIR_CREDIT_BOUNDARY;
|
||||
private static final double MAX_APPROVAL_LOAN_AMOUNT = 100000.00;
|
||||
|
||||
// Interest Rates
|
||||
private static final double YEAR_10_IR = 0.06;
|
||||
private static final double YEAR_15_IR = 0.05;
|
||||
private static final double YEAR_30_IR = 0.04;
|
||||
private static final double YEAR_OTHER_IR = 0.08;
|
||||
|
||||
/*
|
||||
* Class Members
|
||||
*/
|
||||
private int creditScore;
|
||||
private double amount;
|
||||
private int years;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the LoanInfo class
|
||||
*
|
||||
* @param nCreditScore The credit score of the Loan applicant
|
||||
* @param nAmount The dollar amount of the Loan
|
||||
* @param nYears The number of years of the Loan
|
||||
*/
|
||||
public LoanInfo(int nCreditScore, double nAmount, int nYears) {
|
||||
// Ensure credit score is between MIN and MAX, otherwise set it to 300.
|
||||
creditScore = (nCreditScore >= MIN_VALID_CREDIT_SCORE
|
||||
&& nCreditScore <= MAX_VALID_CREDIT_SCORE) ? nCreditScore
|
||||
: MIN_VALID_CREDIT_SCORE;
|
||||
|
||||
amount = (nAmount >= MIN_LOAN_AMOUNT) ? nAmount : MIN_LOAN_AMOUNT;
|
||||
years = (nYears >= MIN_LOAN_YEARS) ? nYears : MIN_LOAN_YEARS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the credit score of the Loan applicant
|
||||
*
|
||||
* @return The Loan applicant's credit score
|
||||
*/
|
||||
public int getCreditScore() {
|
||||
return creditScore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dollar amount of the loan
|
||||
*
|
||||
* @return The dollar amount of the loan
|
||||
*/
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of years of the loan
|
||||
*
|
||||
* @return The number of years of the loan
|
||||
*/
|
||||
public int getYears() {
|
||||
return years;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the loan should be approved based on the information
|
||||
* provided. Is either approved immediately if the credit score is over the
|
||||
* {@link #INSTANT_APPROVAL_CREDIT_SCORE} or if the credit score is over the
|
||||
* {@link #MIN_APPROVAL_CREDIT_SCORE} and the loan amount is below the
|
||||
* {@link #MAX_APPROVAL_LOAN_AMOUNT}.
|
||||
*
|
||||
* @return If the loan should be approved.
|
||||
*/
|
||||
public boolean canApprove() {
|
||||
// Check if the credit score is above the instant approval credit score
|
||||
if (creditScore >= INSTANT_APPROVAL_CREDIT_SCORE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the credit score is above the minimum approval, and the loan
|
||||
// amount is below the maximum
|
||||
if (creditScore >= MIN_APPROVAL_CREDIT_SCORE
|
||||
&& amount < MAX_APPROVAL_LOAN_AMOUNT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the interest rate based on the number of years the loan is for.
|
||||
* Either, {@link #YEAR_10_IR}, {@link #YEAR_15_IR}, {@link #YEAR_30_IR}, or
|
||||
* {@link #YEAR_OTHER_IR}.
|
||||
*
|
||||
* @return The interest rate of the loan.
|
||||
*/
|
||||
public double getInterestRate() {
|
||||
double result;
|
||||
switch (years) {
|
||||
case 10:
|
||||
result = YEAR_10_IR;
|
||||
break;
|
||||
case 15:
|
||||
result = YEAR_15_IR;
|
||||
break;
|
||||
case 30:
|
||||
result = YEAR_30_IR;
|
||||
break;
|
||||
default:
|
||||
result = YEAR_OTHER_IR;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the credit category of the loan based on the credit score of the
|
||||
* applicant.
|
||||
*
|
||||
* @return The credit category
|
||||
*/
|
||||
public String getCreditCategory() {
|
||||
String retString = "";
|
||||
|
||||
if (creditScore >= EXCEPTIONAL_CREDIT_BOUNDARY) {
|
||||
retString = EXCEPTIONAL_CREDIT_STRING;
|
||||
} else if (creditScore >= VGOOD_CREDIT_BOUNDARY) {
|
||||
retString = VGOOD_CREDIT_STRING;
|
||||
} else if (creditScore >= GOOD_CREDIT_BOUNDARY) {
|
||||
retString = GOOD_CREDIT_STRING;
|
||||
} else if (creditScore >= FAIR_CREDIT_BOUNDARY) {
|
||||
retString = FAIR_CREDIT_STRING;
|
||||
} else {
|
||||
retString = POOR_CREDIT_STRING;
|
||||
}
|
||||
|
||||
return retString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(DecimalFormat.getCurrencyInstance().format(amount));
|
||||
builder.append(" @ ");
|
||||
builder.append(
|
||||
DecimalFormat.getPercentInstance().format(getInterestRate()));
|
||||
builder.append(" for ");
|
||||
builder.append(years);
|
||||
builder.append(" years, ");
|
||||
builder.append(getCreditCategory());
|
||||
builder.append(" credit: ");
|
||||
builder.append(canApprove() ? "Approved" : "Denied");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
149
LAB-6/src/uwstout/courses/cs144/labs/lab6/LoanInfoTest.java
Normal file
149
LAB-6/src/uwstout/courses/cs144/labs/lab6/LoanInfoTest.java
Normal file
@@ -0,0 +1,149 @@
|
||||
package uwstout.courses.cs144.labs.lab6;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests the {@link LoanInfo} class
|
||||
*
|
||||
* @author Brett Bender
|
||||
* @version 2022.11.08
|
||||
*/
|
||||
public class LoanInfoTest {
|
||||
|
||||
private static final double DELTA = 0.01;
|
||||
|
||||
private LoanInfo l1;
|
||||
private LoanInfo l2;
|
||||
private LoanInfo l3;
|
||||
private LoanInfo l4;
|
||||
private LoanInfo l5;
|
||||
private LoanInfo l6;
|
||||
private LoanInfo l7;
|
||||
|
||||
/**
|
||||
* Sets the LoanInfoTest class up for testing.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
l1 = new LoanInfo(0, 0, 0);
|
||||
l2 = new LoanInfo(600, 15000, 10);
|
||||
l3 = new LoanInfo(900, 30000, 15);
|
||||
l4 = new LoanInfo(850, 100000, 8);
|
||||
l5 = new LoanInfo(580, 150000, 10);
|
||||
l6 = new LoanInfo(600, 75000, 30);
|
||||
l7 = new LoanInfo(580, 100000, 10);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the LoanInfo constructor
|
||||
*/
|
||||
@Test
|
||||
public void testLoanInfo() {
|
||||
assertEquals(300, l1.getCreditScore());
|
||||
assertEquals(10000, l1.getAmount(), DELTA);
|
||||
assertEquals(5, l1.getYears());
|
||||
|
||||
assertEquals(600, l2.getCreditScore());
|
||||
assertEquals(15000, l2.getAmount(), DELTA);
|
||||
assertEquals(10, l2.getYears());
|
||||
|
||||
assertEquals(300, l3.getCreditScore());
|
||||
assertEquals(30000, l3.getAmount(), DELTA);
|
||||
assertEquals(15, l3.getYears());
|
||||
|
||||
assertEquals(850, l4.getCreditScore());
|
||||
assertEquals(100000, l4.getAmount(), DELTA);
|
||||
assertEquals(8, l4.getYears());
|
||||
|
||||
assertEquals(580, l5.getCreditScore());
|
||||
assertEquals(150000, l5.getAmount(), DELTA);
|
||||
assertEquals(10, l5.getYears());
|
||||
|
||||
assertEquals(600, l6.getCreditScore());
|
||||
assertEquals(75000, l6.getAmount(), DELTA);
|
||||
assertEquals(30, l6.getYears());
|
||||
|
||||
assertEquals(580, l7.getCreditScore());
|
||||
assertEquals(100000, l7.getAmount(), DELTA);
|
||||
assertEquals(10, l7.getYears());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the canApprove method
|
||||
*/
|
||||
@Test
|
||||
public void testCanApprove() {
|
||||
assertEquals(false, l1.canApprove());
|
||||
assertEquals(true, l2.canApprove());
|
||||
assertEquals(false, l3.canApprove());
|
||||
assertEquals(true, l4.canApprove());
|
||||
assertEquals(false, l5.canApprove());
|
||||
assertEquals(true, l6.canApprove());
|
||||
assertEquals(false, l7.canApprove());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getInterestRate method
|
||||
*/
|
||||
@Test
|
||||
public void testGetInterestRate() {
|
||||
assertEquals(0.08, l1.getInterestRate(), DELTA);
|
||||
assertEquals(0.06, l2.getInterestRate(), DELTA);
|
||||
assertEquals(0.05, l3.getInterestRate(), DELTA);
|
||||
assertEquals(0.08, l4.getInterestRate(), DELTA);
|
||||
assertEquals(0.06, l5.getInterestRate(), DELTA);
|
||||
assertEquals(0.04, l6.getInterestRate(), DELTA);
|
||||
assertEquals(0.06, l7.getInterestRate(), DELTA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getCreditCategory method
|
||||
*/
|
||||
@Test
|
||||
public void testGetCreditCategory() {
|
||||
LoanInfo pCLoanInfo = new LoanInfo(300, 0, 0);
|
||||
assertEquals("Poor", pCLoanInfo.getCreditCategory());
|
||||
|
||||
LoanInfo fCLoanInfo = new LoanInfo(580, 0, 0);
|
||||
assertEquals("Fair", fCLoanInfo.getCreditCategory());
|
||||
|
||||
LoanInfo gCLoanInfo = new LoanInfo(670, 0, 0);
|
||||
assertEquals("Good", gCLoanInfo.getCreditCategory());
|
||||
|
||||
LoanInfo vgCLoanInfo = new LoanInfo(740, 0, 0);
|
||||
assertEquals("Very Good", vgCLoanInfo.getCreditCategory());
|
||||
|
||||
LoanInfo eCLoanInfo = new LoanInfo(800, 0, 0);
|
||||
assertEquals("Exceptional", eCLoanInfo.getCreditCategory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the toString method
|
||||
*/
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("$10,000.00 @ 8% for 5 years, Poor credit: Denied",
|
||||
l1.toString());
|
||||
assertEquals("$15,000.00 @ 6% for 10 years, Fair credit: Approved",
|
||||
l2.toString());
|
||||
assertEquals("$30,000.00 @ 5% for 15 years, Poor credit: Denied",
|
||||
l3.toString());
|
||||
assertEquals(
|
||||
"$100,000.00 @ 8% for 8 years, Exceptional credit: Approved",
|
||||
l4.toString());
|
||||
assertEquals("$150,000.00 @ 6% for 10 years, Fair credit: Denied",
|
||||
l5.toString());
|
||||
assertEquals("$75,000.00 @ 4% for 30 years, Fair credit: Approved",
|
||||
l6.toString());
|
||||
assertEquals("$100,000.00 @ 6% for 10 years, Fair credit: Denied",
|
||||
l7.toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user