Question

In: Computer Science

Sanchez Construction Loan Co. makes loans of up to $100,000 for construction projects. There are two...

Sanchez Construction Loan Co. makes loans of up to $100,000 for construction projects. There are two categories of Loans—those to businesses and those to individual applicants.

Write an application that tracks all new construction loans. The application also must calculate the total amount owed at the due date (original loan amount + loan fee). The application should include the following classes:

• Loan —A public abstract class that implements the LoanConstants interface. A Loan includes a loan number, customer last name, amount of loan, interest rate, and term. The constructor requires data for each of the fields except interest rate. Do not allow loan amounts greater than $100,000. Force any loan term that is not one of the three defined in the LoanConstants class to a short-term, 1-year loan. Create a toString() method that displays all the loan data.

• LoanConstants—A public interface class. LoanConstants includes constant values for short-term (1 year), medium-term (3 years), and long-term (5 years) loans. It also contains constants for the company name and the maximum loan amount.

• BusinessLoan—A public class that extends Loan. The BusinessLoan constructor sets the interest rate to 1% more than the current prime interest rate.

• PersonalLoan—A public class that extends Loan. The PersonalLoan constructor sets the interest rate to 2% more than the current prime interest rate.

• CreateLoans— An application that creates an array of five Loans. Prompt the user for the current prime interest rate. Then, in a loop, prompt the user for a loan type and all relevant information for that loan. Store the created Loan objects in the array. When data entry is complete, display all the loans. For example, the program should accept input similar to the sample program execution below:

Welcome to Sanchez Construction
Enter the current prime interest rate as a decimal number, for example, .05
0.08
Is this a (1) Business loan or (2) Personal loan
1
Enter account number
1
Enter name
Joe
Enter loan amount
10000
Enter term
5
Is this a (1) Business loan or (2) Personal loan
2
Enter account number
2
Enter name
Sara
Enter loan amount
5000
Enter term
3
... And so on for 5 total loans

After all loan information is input, the program should output the loans in the following format:

Sanchez Construction
Loan #1   Name: Joe  $10000.0
 for 5 year(s) at 9% interest
Loan #2   Name: Sara  $5000.0
 for 3 year(s) at 10% interest
Loan #3   Name: Mike  $975.0
 for 1 year(s) at 10% interest
Loan #4   Name: Jane  $7000.0
 for 5 year(s) at 9% interest
Loan #5   Name: Peter  $300.0
 for 1 year(s) at 9% interest

====================================================

public class BusinessLoan extends Loan
{
public BusinessLoan(int num, String name, double amt, int yrs, double prime)
{
// write your code here
}
}

===============================================

import java.util.*;
public class CreateLoans implements LoanConstants
{
public static void main(String[] args)
{
// write your code here
}
}

===============================================

public abstract class Loan implements LoanConstants
{
protected int loanNum;
protected String lastName;
protected double amount;
protected double rate;
protected int term;
public Loan(int num, String name, double amt, int yrs)
{
// write your code here
}
public String toString()
{
// write your code here
}

public boolean equals(Loan loan)
{
// write your code here
}
}

=========================================

public interface LoanConstants
{
public static final int MAXLOAN = 100000;
public static final int SHORT_TERM = 1;
public static final int MEDIUM_TERM = 3;
public static final int LONG_TERM = 5;
public static final String COMPANY = "Sanchez Construction";
}

============================================

public class PersonalLoan extends Loan
{
public PersonalLoan(int num, String name, double amt, int yrs, double prime)
{
// write your code here
}
}

Solutions

Expert Solution

CODE :

Interface LoanConstants:

public interface LoanConstants {
  
   public static final int MAXLOAN = 100000;
   public static final int SHORT_TERM = 1;
   public static final int MEDIUM_TERM = 3;
   public static final int LONG_TERM = 5;
   public static final String COMPANY = "Sanchez Construction";

}

Class Loan :

public abstract class Loan implements LoanConstants
{
   protected int loanNum;
   protected String lastName;
   protected double amount;
   protected double rate;
   protected int term;
   public Loan(int num, String name, double amt, int yrs)
   {
   if(amt > 100000)
       throw new IllegalArgumentException("Loan Amount could not be greater than $100,000");
  
   loanNum = num;
   lastName = name;
   amount = amt;
  
   if(yrs == MEDIUM_TERM || yrs == LONG_TERM)
       term = yrs;
   else
       term = SHORT_TERM;
          
   }

   public boolean equals(Loan obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Loan other = (Loan) obj;
       if (Double.doubleToLongBits(amount) != Double.doubleToLongBits(other.amount))
           return false;
       if (lastName == null) {
           if (other.lastName != null)
               return false;
       } else if (!lastName.equals(other.lastName))
           return false;
       if (loanNum != other.loanNum)
           return false;
       if (Double.doubleToLongBits(rate) != Double.doubleToLongBits(other.rate))
           return false;
       if (term != other.term)
           return false;
       return true;
   }

   @Override
   public String toString() {
       return "Loan #" + loanNum + " Name: " + lastName + " $" + amount + "\n for " + term
               + " year(s) at " + Math.round(rate*100.0*100.0)/100.0 + "% interest";
   }
  
}

Class BusinessLoan :

public class BusinessLoan extends Loan
{
   public BusinessLoan(int num, String name, double amt, int yrs, double prime)
   {
   super(num,name,amt,yrs);
   this.rate = prime + 0.01;
   }
}

Class PersonalLoan :

public class PersonalLoan extends Loan
{
   public PersonalLoan(int num, String name, double amt, int yrs, double prime)
   {
       super(num,name,amt,yrs);
       this.rate = prime + 0.02;
   }
}

Class CreateLoans :

import java.util.*;
public class CreateLoans implements LoanConstants
{
   public static void main(String[] args)
   {
       Loan arrLoan[] = new Loan[5];
       Scanner sc = new Scanner(System.in);
       double primeRate,amt;
       int loanType,acctNum,term;
      
       String name;
      
       System.out.println("Welcome to " + COMPANY );
       System.out.println("Enter the current prime interest rate as a decimal number, for example, .05");
      
       primeRate = Double.parseDouble(sc.nextLine());
      
       for(int i=0; i < arrLoan.length; i++)
       {
           System.out.println("Is this a (1) Business loan or (2) Personal loan");
           loanType = Integer.parseInt(sc.nextLine());
          
           System.out.println("Enter account number");
           acctNum = Integer.parseInt(sc.nextLine());
          
           System.out.println("Enter name");
           name = sc.nextLine();
          
           System.out.println("Enter loan amount");
           amt = Double.parseDouble(sc.nextLine());
          
           System.out.println("Enter term");
           term = Integer.parseInt(sc.nextLine());
          
           if(loanType == 1)          
               arrLoan[i] = new BusinessLoan(acctNum,name,amt,term,primeRate);
           else if(loanType == 2)          
               arrLoan[i] = new PersonalLoan(acctNum,name,amt,term,primeRate);
           else {
               throw new IllegalArgumentException("Please Select proper loan type");
           }          
       }
      
       for(int j=0; j < arrLoan.length; j++)
           System.out.println(arrLoan[j]);
      
       sc.close();
      
   }
}

OUTPUT :

I have tested with two inputs.


Related Solutions

Pittsburg Savings & Loan makes four kinds of loans. These loans, with the yearly interest rate...
Pittsburg Savings & Loan makes four kinds of loans. These loans, with the yearly interest rate charged to customers, are shown in the table below. Type of Loan                              Interest Charged (%, percent) Commercial Loans                                           8 Home Mortgages                                  4 Home Improvements                              6 Short-term revolving loans                     10 The bank has $25 million in available funds. Its objective is to maximize yield on investment. The demand for short-term revolving loans never exceeds $10 million. Also there are policies and regulations...
E-Z Loan, Co. makes loans to high-risk borrowers. E-Z borrows from its bank and then lends...
E-Z Loan, Co. makes loans to high-risk borrowers. E-Z borrows from its bank and then lends money to people with bad credit. The bank requires E-Z Loan to submit quarterly financial statements in order to keep its line of credit. E-Z’s main asset is Accounts Receivable. Therefore, Bad Debts Expense and Allowance for Bad Debts are important accounts. Slade McMurphy, the owner of E-Z Loan, wants net income to increase in a smooth pattern rather than increase in some periods...
E-Z Loan Co. makes loans to high-risk borrowers. E-Z borrows from its bank and then lends...
E-Z Loan Co. makes loans to high-risk borrowers. E-Z borrows from its bank and then lends money to people who have bad credit. The bank requires E-Z Loan to submit quarterly financial statements in order to keep its line of credit. E-Z’s main asset is Accounts Receivable. Therefore, Bad Debts Expense and Allowance for Bad Debts are important accounts. Slade McMurphy, the controller of E-Z Loan, wants net income to increase in a smooth pattern rather than increase in some...
You currently have two loans outstanding: a car loan and a student loan. The car loan...
You currently have two loans outstanding: a car loan and a student loan. The car loan requires that you pay $329 per month, starting next month for 28 more months. Your student loan is requires that you pay $145 per month, starting next month for the next 119 months. A debt consolidation company gives you the following offer: It will pay off the balances of your two loans today and then charge you $487 per month for the next 41...
You currently have two loans outstanding: a car loan and a student loan. The car loan...
You currently have two loans outstanding: a car loan and a student loan. The car loan requires that you pay $325 per month, starting next month for 26 more months. Your student loan is requires that you pay $87 per month, starting next month for the next 38 months. A debt consolidation company gives you the following offer: It will pay off the balances of your two loans today and then charge you $501 per month for the next 45...
You currently have two loans outstanding: a car loan and a student loan. The car loan...
You currently have two loans outstanding: a car loan and a student loan. The car loan requires that you pay $413 per month, starting next month for 28 more months. Your student loan is requires that you pay $89 per month, starting next month for the next 75 months. A debt consolidation company gives you the following offer: It will pay off the balances of your two loans today and then charge you $508 per month for the next 37...
You currently have two loans outstanding: a car loan and a student loan. The car loan...
You currently have two loans outstanding: a car loan and a student loan. The car loan requires that you pay $313 per month, starting next month for 35 more months. Your student loan is requires that you pay $133 per month, starting next month for the next 115 months. A debt consolidation company gives you the following offer: It will pay off the balances of your two loans today and then charge you $451 per month for the next 45...
You currently have two loans outstanding: a car loan and astudent loan. The car loan...
You currently have two loans outstanding: a car loan and a student loan. The car loan requires that you pay $316 per month, starting next month for 26 more months. Your student loan is requires that you pay $103 per month, starting next month for the next 69 months. A debt consolidation company gives you the following offer: It will pay off the balances of your two loans today and then charge you $475 per month for the next 43...
A loan shop in town offers emergency loans of up to $800 for 1 month. The...
A loan shop in town offers emergency loans of up to $800 for 1 month. The shop charges a 4% fee of the amount for the 1-month period. If a person borrows $800for one month, what is: the nominal interest rate per year? the effective rate per year?
You are considering two possible fixed-rate level payment loans, Loan A and Loan B. Loan A...
You are considering two possible fixed-rate level payment loans, Loan A and Loan B. Loan A has the following information: loan amount is $300,000, 6.6% contract rate, 30 year maturity with monthly payments, it has a 1.5% upfront fee and a mortgage insurance fee of 1%. Loan B has the following information: loan amount is $300,000, 6.35% contract rate, 30 year maturity with monthly payments, it has a 4% upfront fee and a mortgage insurance fee of 1%. Calculate the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT