0% found this document useful (0 votes)
360 views

Java Last Exercise

The document defines an abstract Loan class and two subclasses: BusinessLoan and PersonalLoan. BusinessLoan and PersonalLoan both override the interest rate of the Loan superclass by adding 1 and 2 respectively. The main method creates a Loan array, prompts the user to choose between a business or personal loan, collects input to create the chosen loan type and stores it in the array. It then prints out the details of each loan in the array.

Uploaded by

Lovely Panlilio
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
360 views

Java Last Exercise

The document defines an abstract Loan class and two subclasses: BusinessLoan and PersonalLoan. BusinessLoan and PersonalLoan both override the interest rate of the Loan superclass by adding 1 and 2 respectively. The main method creates a Loan array, prompts the user to choose between a business or personal loan, collects input to create the chosen loan type and stores it in the array. It then prints out the details of each loan in the array.

Uploaded by

Lovely Panlilio
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

public class BusinessLoan extends Loan{ public BusinessLoan(int h, String j, double k, int l){ super(h,j,k,l); super.intRate = super.

intRate + 1; } } ________________________________________________________________________________ public class PersonalLoan extends Loan{ public PersonalLoan(int h, String j, double k, int l){ super(h,j,k,l); super.intRate = super.intRate + 2; } } ________________________________________________________________________________ _____ public interface LoanConstants{ final final final final final } ________________________________________________________________________________ _________ public abstract class Loan implements LoanConstants { private String name; private double amount; public double intRate=10.0; private int num,term; public Loan(int h, String j, double k, int l){ num = h; name = j; amount = k; term = l; if(loanAmount > MAX_LOAN_AMOUNT){ System.out.println("EWWOW"); amount = 0.0; } if(term != SHORT_TERM && term != MEDIUM_TERM && term != LONG_TERM){ System.out.println("EWWOW"); term = 1; int SHORT_TERM = 1; int MEDIUM_TERM = 3; int LONG_TERM = 5; String COMPANY_NAME = "Sanchez and Construction Loan Co."; double MAX_LOAN_AMOUNT = 100000.00;

} } public String toString(){ String e = "Loan Number = " + loanNumber + "Costumer Last Name = " + cLastName + "Loan Amount = " + loanAmount + "Interest Rate = " + intRate + "Term = " + term + "Total Amount Owed: " + (amount + (amount * (intRate/100))); return e; } } ________________________________________________________________________________ _____________________ import java.util.Scanner; public class CreateLoans { public static void main(String[] args){ Scanner s = new Scanner(System.in); int num,term,choice; String name; double amount; Loan[] w = new Loan[5]; for(int i=0;i<MAX_SIZE;i++){ System.out.println("Choose Loan Type:1 Business Loan 2 Personal Loan"); choice = s.nextInt(); if(choice == 1){ System.out.print("\nEnter Loan Number: " ); num = s.nextInt(); System.out.print("Enter Last Name: "); s.nextLine(); name = s.nextLine(); System.out.print("Enter Loan Amount: "); amount = s.nextDouble(); System.out.print("Enter Number of Terms: "); term = s.nextInt(); w[i] = new BusinessLoan(num,name,amount, term); } else if(choice == 2){ System.out.print("\nEnter Loan Number: " ); num = s.nextInt(); System.out.print("Enter Last Name: "); s.nextLine(); name = s.nextLine(); System.out.print("Enter Loan Amount: "); amount = s.nextDouble(); System.out.print("Enter Number of Terms: "); term = s.nextInt();

w[i] = new PersonalLoan(num,name,amount, term); } else System.out.println("EWWOW! MUWST BEW WONE OW TWO"); } for(int i=0;i<w.length;i++){ System.out.println(w[i].toString()); } }

You might also like