Java Case Study

Loan Calculator — Loan Summary Builder

A Java console application that builds formatted loan summaries, including borrower name, loan amount, term, interest rate, and a calculated end date using a helper class. A simple test runner validates multiple scenarios.

Screenshots

Loan Class

Screenshot of the Loan class in Java.

Represents the core loan data: borrower, amount, term, interest rate, and summary output.

LoanCreator Logic

Screenshot of the LoanCreator class in Java.

Handles user inputs and builds the loan summary string, applying defaults when needed.

Test Code

Screenshot of the loan test logic in Java.

Original JUnit-style tests used to validate output before converting to a standalone runner.

Test Runner Output

Screenshot of LoanCreator test runner console output.

Console output showing several loan scenarios being created and verified against expected summaries.

Project Overview

This assignment focused on working with methods, parameters, and formatted output in Java. The program takes in borrower information and loan details, fills in defaults when some values are missing, and then produces a readable summary. A helper class, LoanDateCalculator, is used to determine the end date of the loan based on the term.

The design separates responsibilities so that each class has a clear purpose: one for building the loan, one for calculating dates, and one for testing the logic. This makes the code easier to extend and maintain.

Key Logic (Summary Builder)

A simplified example of how the loan summary string is built:

public class LoanCreator {

    public String execute(String firstName, String lastName,
                          Integer amount, Integer termYears, Double interestRate) {

        String borrower = firstName + " " + lastName;
        int finalAmount = amount != null ? amount : 20000;
        int finalTerm   = termYears != null ? termYears : 36;
        double finalRate = interestRate != null ? interestRate : 5.0;

        String endDate = LoanDateCalculator.calculate(finalTerm);

        return "The loan for: " + borrower + "\n" +
               "The loan amount is " + finalAmount + "\n" +
               "The term is " + finalTerm + " years\n" +
               "The interest rate is " + finalRate + "%\n" +
               "The end date of the loan will be: " + endDate;
    }
}

The real project includes more context and validation, but this excerpt shows the core idea: apply defaults when needed, delegate date calculation, and build a predictable summary string.

What I Learned

Explore the Code

You can review the full implementation, including the date calculator and test runner, on GitHub.