SHARE
TWEET

Untitled

a guest Oct 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //McDonaghNiall19LabEx1 - Niall McDonagh
  2. //Calculates loan offers and charges
  3.  
  4. import java.io.*; //ignore 1
  5. import java.util.Scanner;
  6.  
  7. public class McDonaghNiall19LabEx1
  8. {
  9.     public static void main(String[] args)throws FileNotFoundException //ignore 2
  10.     {
  11.          Scanner console = new Scanner(new FileReader("LabEx1.txt")); //ignore 3
  12.  
  13.         // Constants
  14.         final int MONTHS = 12;
  15.         final double MORTG_DEPOSIT = 0.2;
  16.         final int MONTHLY_DED_2000 = 30;
  17.         final int MONTHLY_DED_3000 = 50;
  18.         final int MONTHLY_DED_20000 = 100;
  19.         final double TRANS_FEE = 10.00;
  20.         final double MORTGAGE_CAT = 0.045;
  21.         final double CAR_CAT = 0.074;
  22.         final double EDUC_CAT = 0.0599;
  23.         final double PERSON_CAT = 0.0859;
  24.         final double INSURANCE_MORTG=15.00;
  25.         final double INSURANCE_OTHER=5.00;
  26.  
  27.         // Variables
  28.         int years = 0;
  29.         double loanAmt = 0, apr = 0, monthlyBasic = 0;
  30.         int i;
  31.         char type;
  32.         int loanNum;
  33.         double aprType=0;
  34.         char customerType;
  35.         int newCustomerCount = 0;
  36.         int existingCustomerCount = 0;
  37.         String customerCat="";
  38.         char insurance;
  39.         double loanTotal;
  40.         int loanMonths = 0;
  41.         double loanDeduct = 0;
  42.         double interest = 0;
  43.         double firstMonthPayment = 0;
  44.         double monthlyPayment = 0;
  45.         double mortgageDeposit = 0;
  46.         double insuranceCover = 0;
  47.         double loanRepay = 0;
  48.         double monthlyBasicTotal = 0;
  49.         double loanRepayTotal = 0;
  50.         double interestAmtTotal = 0;
  51.         double insCover = 0;
  52.         double MortgDeposit = 0;
  53.         double CustDeductTotal = 0;
  54.         double LoanTotal = 0;
  55.         double FirstMonthTotal = 0;
  56.         double regularMonthsTotal = 0;
  57.         //Scanner console = new Scanner(System.in);
  58.  
  59.         // Ask number of loans
  60.         // Preliminary Input
  61.         System.out.println();
  62.         System.out.print("Enter number of loans: ");
  63.         loanNum = console.nextInt(); // console.nextDouble(); console.next().charAt(0);
  64.  
  65.         //Header
  66.         System.out.println();
  67.         System.out.print(" Lab Exam 1   Loan    Loan    Loan    APR Monthly Interest    Ins X/E Cust    Loan    First   Regular \n");
  68.         System.out.print(" Niall McD    Num     Type    Months  %   Monthly Basic   Amt Cover   Deduct  Total   Month   Months \n");
  69.         System.out.print(" ===================================================================================================================== \n");
  70.  
  71.         for (i = 1; i <= loanNum; ++i)
  72.                 {
  73.                     // Line Input
  74.                     System.out.println("Type/AMT/Yrs/Status/ins: ");
  75.  
  76.                     //myInt = console.nextInt();
  77.                     //myDouble = console.nextDouble();
  78.                     type = console.next().charAt(0);
  79.                     loanAmt = console.nextDouble();
  80.                     years = console.nextInt();
  81.                     customerType = console.next().charAt(0);
  82.                     insurance = console.next().charAt(0);
  83.  
  84.                     if (type == 'P' || type == 'p') {
  85.                          customerCat = "Personal";
  86.                          aprType = PERSON_CAT * 100;
  87.                     }
  88.                     else if (type == 'C' || type == 'c') {
  89.                          customerCat = "Car";
  90.                          aprType = CAR_CAT * 100;
  91.                     }
  92.  
  93.                     else if (type == 'M' || type == 'm') {
  94.                          customerCat = "Mortgage";
  95.                          aprType = MORTGAGE_CAT * 100;
  96.  
  97.                     }
  98.                     else if (type == 'E' || type == 'e') {
  99.                          customerCat = "Education";
  100.                          aprType = EDUC_CAT * 100;
  101.                     }
  102.  
  103.                     else {
  104.                          customerCat = "Unknown";
  105.                     }
  106.  
  107.  
  108.  
  109.                     //Loan deduction
  110.                     if (customerType == 'W' || customerType == 'w')
  111.                         ++newCustomerCount;
  112.                     {
  113.                         if(loanAmt >= 2000.00)
  114.                         {
  115.                             loanDeduct = MONTHLY_DED_2000;
  116.                         }
  117.                         else if(customerType == 'X' || customerType == 'x' || loanAmt >=3000.00)
  118.                         {
  119.                             loanDeduct = MONTHLY_DED_3000;
  120.                             ++existingCustomerCount;;
  121.                         }
  122.                         else if(customerType == 'X' || customerType == 'x' || loanAmt >=20000.00)
  123.                         {
  124.                             loanDeduct = MONTHLY_DED_20000;
  125.                             ++existingCustomerCount;;
  126.                         }
  127.                         else
  128.                         {
  129.                             loanDeduct = 0;
  130.                         }
  131.  
  132.                     }
  133.  
  134.                     //Insurance Y/N
  135.                     if (insurance == 'Y' || insurance == 'y')
  136.                     {
  137.                         if(customerCat == "Mortgage")
  138.                         {
  139.                             insuranceCover = INSURANCE_MORTG;
  140.                         }
  141.                         else if(insurance =='N' || insurance =='n')
  142.                         {
  143.                             insuranceCover = 0;
  144.                         }
  145.                         else
  146.                         {
  147.                             insuranceCover = INSURANCE_MORTG;
  148.                         }
  149.  
  150.                     }
  151.  
  152.                     // Mortgage deposit
  153.  
  154.                     if (type == 'M' || type == 'm')
  155.                     {
  156.                         mortgageDeposit = MORTG_DEPOSIT * loanAmt;
  157.                     }
  158.  
  159.                     // Existing customer count
  160.  
  161.                     if (customerType == 'X' || customerType == 'x')
  162.                     {
  163.                         ++existingCustomerCount;
  164.                     }
  165.  
  166.                     // Calculations here
  167.  
  168.                     loanMonths = years * 12;
  169.                     apr = aprType / 100;
  170.                     loanTotal = interest + TRANS_FEE + insuranceCover + monthlyBasic;
  171.                     firstMonthPayment = TRANS_FEE + monthlyBasic + insuranceCover;
  172.                     monthlyPayment = monthlyBasic + insuranceCover;
  173.                     loanRepay = monthlyPayment * loanMonths;
  174.                     interest = loanRepay - loanAmt;
  175.                     monthlyBasic = loanAmt * apr /(MONTHS * (1 - 1 /(Math.pow((1+apr/MONTHS),(MONTHS*years)))));
  176.  
  177.                     //Output - unformatted
  178.                     System.out.println("        " + i + "   " + customerCat + " " + loanMonths + "  " + aprType + " " + monthlyBasic + "    " + loanRepay + "   " + interest + "    " + insuranceCover + "  " + mortgageDeposit + " " + loanDeduct + "  " + loanTotal + "   " + firstMonthPayment + "   " + monthlyPayment);
  179.  
  180.                     //Output - formatted
  181.                     //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  );
  182.  
  183.         } // for
  184.  
  185.         System.out.print("\n ============================================================================================================ \n");
  186.  
  187.     /*  //Totals
  188.         System.out.println("        " + monthlyBasicTotal);
  189.         System.out.println();
  190.         System.out.println();
  191.         System.out.println();
  192. */
  193.         //Customer information
  194.         System.out.println(newCustomerCount + " new customers today");
  195.         System.out.println();
  196.         System.out.println(existingCustomerCount + " existing customers today");
  197.         System.out.println();
  198.     } // main
  199.  
  200. }// class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top