You are on page 1of 2

Loan.

java
package com.packages;
import javax.swing.*;
import java.io.*;
import java.text.DecimalFormat;
import java.util.Scanner;

class Main {

public static void main(String[] args) {


//variables
String customer;
int account_type, years;
double loan, loan_initial = 0, interest = 0, service_fee, rate =
0,
total = 0;
Scanner sc = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#,###,###,###.00");
//Data Entry
System.out.print("Loan.java\n\n");
System.out.print("Enter Applicant's Name: ");
customer = sc.nextLine();
System.out.print("Enter Loan Amount: ");
loan = sc.nextDouble();
loan_initial = loan;
System.out.print("Enter Loan type (1,2,3): ");
account_type = sc.nextInt();
System.out.print("Enter Number of Years for the Loan: ");
years = sc.nextInt();
System.out.print("Enter Service Charge: Php");
service_fee = sc.nextDouble();
//Conditionals
switch (account_type) {
case 1:
rate = 0.05;
for (int i = 0; i < years; i++) {
interest = loan * rate;
loan = loan + interest;
}
total = service_fee + loan;
break;
case 2:
rate = 0.07;
for (int i = 0; i < years; i++) {
interest = loan * rate;
loan = loan + interest;
}
total = service_fee + loan;
break;
case 3:
rate = 0.09;
for (int i = 0; i < years; i++) {
interest = loan * rate;
loan = loan + interest;
}
total = service_fee + loan;
break;
default:
System.out.println("Error: Invalid Input.");
System.exit(0);
break;
}
System.out.println("\n\nApplicant Name: " + customer);
System.out.println("Initial Loan Amount: Php" + loan_initial);
System.out.println("Interest Rate Per Year:" + rate);
System.out.println("Total Interest: Php" + df.format(interest));
System.out.println("Loan Amount with Interest: Php" +
df.format(loan));
System.out.println("Service Charge: Php" +
df.format(service_fee));
System.out.println("Total Loan Amount: Php" + df.format(total));
}
}

You might also like