Copy/paste this code into a file IfElse.java:

// This program demonstrates if/else statement
// Electronic loan approval

public class IfElse {

    public static void main (String [] args) {
	// For simplicity the numbers are fixed, 
	// not obtained as input
	double loan_amount = 5500;
	// yearly salary
	double salary = 30000;    
	
	// approval policy: a loan is approved if
	// the total amount is no more than 20% of the salary
	if (loan_amount * 5 > salary) {
	    System.out.println("Unfortunately you can't get a loan");
	} else { // loan is approved. 
	    System.out.println("Your loan has been approved. ");
	    // figure out APR: if the loan is for more than $5000
	    // then it's 5%, otherwise it's 7%
	    if (loan_amount < 5000) {
		System.out.println("The APR is 7%");
	    } else {
		System.out.println("The APR is 5%");
	    }
	}
    }
}

This is an example from CSci 1211 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.