Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //McDonaghNiall19LabEx1 - Niall McDonagh
- //Calculates loan offers and charges
- import java.io.*; //ignore 1
- import java.util.Scanner;
- public class McDonaghNiall19LabEx1
- {
- public static void main(String[] args)throws FileNotFoundException //ignore 2
- {
- Scanner console = new Scanner(new FileReader("LabEx1.txt")); //ignore 3
- // Constants
- final int MONTHS = 12;
- final double MORTG_DEPOSIT = 0.2;
- final int MONTHLY_DED_2000 = 30;
- final int MONTHLY_DED_3000 = 50;
- final int MONTHLY_DED_20000 = 100;
- final double TRANS_FEE = 10.00;
- final double MORTGAGE_CAT = 0.045;
- final double CAR_CAT = 0.074;
- final double EDUC_CAT = 0.0599;
- final double PERSON_CAT = 0.0859;
- final double INSURANCE_MORTG=15.00;
- final double INSURANCE_OTHER=5.00;
- // Variables
- int years = 0;
- double loanAmt = 0, apr = 0, monthlyBasic = 0;
- int i;
- char type;
- int loanNum;
- double aprType=0;
- char customerType;
- int newCustomerCount = 0;
- int existingCustomerCount = 0;
- String customerCat="";
- char insurance;
- double loanTotal;
- int loanMonths = 0;
- double loanDeduct = 0;
- double interest = 0;
- double firstMonthPayment = 0;
- double monthlyPayment = 0;
- double mortgageDeposit = 0;
- double insuranceCover = 0;
- double loanRepay = 0;
- double monthlyBasicTotal = 0;
- double loanRepayTotal = 0;
- double interestAmtTotal = 0;
- double insCover = 0;
- double MortgDeposit = 0;
- double CustDeductTotal = 0;
- double LoanTotal = 0;
- double FirstMonthTotal = 0;
- double regularMonthsTotal = 0;
- //Scanner console = new Scanner(System.in);
- // Ask number of loans
- // Preliminary Input
- System.out.println();
- System.out.print("Enter number of loans: ");
- loanNum = console.nextInt(); // console.nextDouble(); console.next().charAt(0);
- //Header
- System.out.println();
- System.out.print(" Lab Exam 1 Loan Loan Loan APR Monthly Interest Ins X/E Cust Loan First Regular \n");
- System.out.print(" Niall McD Num Type Months % Monthly Basic Amt Cover Deduct Total Month Months \n");
- System.out.print(" ===================================================================================================================== \n");
- for (i = 1; i <= loanNum; ++i)
- {
- // Line Input
- System.out.println("Type/AMT/Yrs/Status/ins: ");
- //myInt = console.nextInt();
- //myDouble = console.nextDouble();
- type = console.next().charAt(0);
- loanAmt = console.nextDouble();
- years = console.nextInt();
- customerType = console.next().charAt(0);
- insurance = console.next().charAt(0);
- if (type == 'P' || type == 'p') {
- customerCat = "Personal";
- aprType = PERSON_CAT * 100;
- }
- else if (type == 'C' || type == 'c') {
- customerCat = "Car";
- aprType = CAR_CAT * 100;
- }
- else if (type == 'M' || type == 'm') {
- customerCat = "Mortgage";
- aprType = MORTGAGE_CAT * 100;
- }
- else if (type == 'E' || type == 'e') {
- customerCat = "Education";
- aprType = EDUC_CAT * 100;
- }
- else {
- customerCat = "Unknown";
- }
- //Loan deduction
- if (customerType == 'W' || customerType == 'w')
- ++newCustomerCount;
- {
- if(loanAmt >= 2000.00)
- {
- loanDeduct = MONTHLY_DED_2000;
- }
- else if(customerType == 'X' || customerType == 'x' || loanAmt >=3000.00)
- {
- loanDeduct = MONTHLY_DED_3000;
- ++existingCustomerCount;;
- }
- else if(customerType == 'X' || customerType == 'x' || loanAmt >=20000.00)
- {
- loanDeduct = MONTHLY_DED_20000;
- ++existingCustomerCount;;
- }
- else
- {
- loanDeduct = 0;
- }
- }
- //Insurance Y/N
- if (insurance == 'Y' || insurance == 'y')
- {
- if(customerCat == "Mortgage")
- {
- insuranceCover = INSURANCE_MORTG;
- }
- else if(insurance =='N' || insurance =='n')
- {
- insuranceCover = 0;
- }
- else
- {
- insuranceCover = INSURANCE_MORTG;
- }
- }
- // Mortgage deposit
- if (type == 'M' || type == 'm')
- {
- mortgageDeposit = MORTG_DEPOSIT * loanAmt;
- }
- // Existing customer count
- if (customerType == 'X' || customerType == 'x')
- {
- ++existingCustomerCount;
- }
- // Calculations here
- loanMonths = years * 12;
- apr = aprType / 100;
- loanTotal = interest + TRANS_FEE + insuranceCover + monthlyBasic;
- firstMonthPayment = TRANS_FEE + monthlyBasic + insuranceCover;
- monthlyPayment = monthlyBasic + insuranceCover;
- loanRepay = monthlyPayment * loanMonths;
- interest = loanRepay - loanAmt;
- monthlyBasic = loanAmt * apr /(MONTHS * (1 - 1 /(Math.pow((1+apr/MONTHS),(MONTHS*years)))));
- //Output - unformatted
- System.out.println(" " + i + " " + customerCat + " " + loanMonths + " " + aprType + " " + monthlyBasic + " " + loanRepay + " " + interest + " " + insuranceCover + " " + mortgageDeposit + " " + loanDeduct + " " + loanTotal + " " + firstMonthPayment + " " + monthlyPayment);
- //Output - formatted
- //System.out.printf("%5d %6s %9d %5.2f %10.2f %2.2f ", i, customerCat, loanMonths, apr, monthlyBasic , loanRepay, interest, insuranceCover, mortgageDeposit, loanDeduct, loanTotal, firstMonthPayment, MonthlyPayment );
- } // for
- System.out.print("\n ============================================================================================================ \n");
- /* //Totals
- System.out.println(" " + monthlyBasicTotal);
- System.out.println();
- System.out.println();
- System.out.println();
- */
- //Customer information
- System.out.println(newCustomerCount + " new customers today");
- System.out.println();
- System.out.println(existingCustomerCount + " existing customers today");
- System.out.println();
- } // main
- }// class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement