CreateLoans Code

CreateLoans.java

/*
 * Mark Hesser
 * HesserCAN 
 * [email protected]
 * www.hessercan.com
 */
 
package createloans;
 
/**
 * @author mark
 */
public class CreateLoans 
{
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
        Loan[] loans = new Loan[5];
 
        loans[0] = new PersonalLoan(1, "Hesser", 34000, 5);
        loans[1] = new BusinessLoan(2, "Ireland", 1560000, 5);
        loans[2] = new PersonalLoan(3, "Woods", 58600, 5);
        loans[3] = new BusinessLoan(4, "Bartges", 90000, 5);
        loans[4] = new PersonalLoan(5, "Confer", 10200, 5);
 
        String info = "";
        for (int i = 0; i < loans.length; i++)
        {
            if (loans.length == (i + 1))
                info += loans[i].toString() + "\n";
            else
                info += loans[i].toString() + "\n\n";
        }
        DisplayInfo(info);
    }
 
    static void DisplayInfo(String info)
    {
        System.out.println(info);
    }
}

Loan.java

/*
 * Mark Hesser
 * HesserCAN 
 * [email protected]
 * www.hessercan.com
 */
 
package createloans;
 
/**
 * @author mark
 */
public abstract class Loan implements LoanConstants
{
    private final int loanNum, term;
    private final String custLast;
    private final double loanAmt;
    protected double interestRate;
 
    //Default Constructor
 
    /**
     *
     * @param ln
     * @param cl
     * @param loan
     * @param t
     */
    public Loan(int ln, String cl, double loan, int t)
    {
        loanNum = ln;
        custLast = cl;
 
        //Sets Loan Amount based on input
        //Doesn't allow over Max
        if (loan > MAX_LOAN)
            loanAmt = MAX_LOAN;
        else if (loan < 0) 
            loanAmt = 0;
        else
            loanAmt = loan;
 
        if (t > 0)
        {
            if (t == SHORT_TERM)
                term = SHORT_TERM;
            else if (t == MEDIUM_TERM)
                term = MEDIUM_TERM;
            else if (t >= LONG_TERM)
                term = LONG_TERM;
            else
                term = SHORT_TERM;
        }
        else
            term = SHORT_TERM;
    }
 
    public int getLoanNum()
    {
        return loanNum;
    }
    public String getCustLast()
    {
        return custLast;
    }
    public double getLoanAmt()
    {
        return loanAmt;
    }
    public String getLoanTermStr()
    {
        switch (term)
        {
            case LONG_TERM:
                return "Long Term (Five Years)";
            case MEDIUM_TERM:
                return "Medium Term (Three Years)";
            default:
                return "Short Term (One Year)";
        }
    }
 
    //Forces InterestRate to be set by the Children.
    abstract void setInterestRate();
 
    @Override
    public String toString()
    {
        return String.format("Loan Number: %d\nCustomer: %s \nLoan: $%.2f "
                + "\nInterest Rate: %.0f%% \nTerm: %s", 
                loanNum, custLast, loanAmt, (interestRate * 100), getLoanTermStr());
    }
}

LoanConstants.java

/*
 * Mark Hesser
 * HesserCAN 
 * [email protected]
 * www.hessercan.com
 */
package createloans;
 
/**
 *
 * @author mark
 */
public interface LoanConstants
{
    public final String COMPANY_NAME = "Sanchez Construction Loan Co.";
    public final int SHORT_TERM = 1;
    public final int MEDIUM_TERM = 3;
    public final int LONG_TERM = 5;
    public final double MAX_LOAN = 100000;
}

PersonalLoan.java

/*
 * Mark Hesser
 * HesserCAN 
 * [email protected]
 * www.hessercan.com
 */
 
package createloans;
 
/**
 * @author mark
 */
public class PersonalLoan extends Loan
{
    private final double PLIR = .01;
 
    /**
     *
     * @param ln
     * @param cl
     * @param loan
     * @param t
     */
    public PersonalLoan(int ln, String cl, double loan, int t)
    {
        super(ln, cl, loan, t);
        setInterestRate();
    }
 
    void setInterestRate()
    {
        interestRate = PLIR;
    }
}

BusinessLoan.java

/*
 * Mark Hesser
 * HesserCAN 
 * [email protected]
 * www.hessercan.com
 */
 
package createloans;
 
/**
 * @author mark
 */
public class BusinessLoan extends Loan
{
    private final double BLIR = .02;
 
    /**
     *
     * @param ln
     * @param cl
     * @param loan
     * @param t
     */
    public BusinessLoan(int ln, String cl, double loan, int t)
    {
        super(ln, cl, loan, t);
        setInterestRate();
    }
 
    void setInterestRate()
    {
        interestRate = BLIR;
    }
}