Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public static void main(String[1 args) t 121 13 14 15 16 Scanner input new Scann

ID: 3888404 • Letter: P

Question

public static void main(String[1 args) t 121 13 14 15 16 Scanner input new Scanner(System.in); System.out.println("What is the loan amount? ") int loanamount = input . nextInt(); 18 19 20 21 System.out.println("What is the down payment? "): int downpayment = input . next!nt(); out.print("Have you held your current job for at least a year? "); current job String input . next(); 23 24 25 26 27 28 System.out.println("what is your annual salary? "); int annualsalary = input.next Int(); if(downpayment >= (.2 * Ioanamount)) { System.out.println("You are eligilble for this loan ofoanamount): System.out.printf("You are eliglible for this loan of "loanamount); System.out.printf("You are not eligible for this loan of $" loanamount): else if ((currentjob-= "yes") 66 (annualsalary >_ (loanamount * .5))) { 31 32 elset 34 35 main> if (downpayment >= (0.2. Ioanamount) else if ((current ob== yes")&& annua sala y> loa anc , week4labtue.Week4LabTue> Output-week4 LabTue(run) run: What is the loan amount? 50000 What is the down payment? 10000 Have you held your current job for at least a year? yes What is your annual salary? 20000 You are eligilble for this loan of 50080 BUILD SUCCESSFUL (total time: 12 seconds)

Explanation / Answer

This program works fine for first condtion

if(downpayment >= (.2*loanamount))

and the else condtion(last condtion)

but it does not work properly for the condition where currentjob=yes and annual salary is greater than the

amount: (loanamount*.5)

I mean the below condtion does not work

else if((currentjob=="yes") && (annualsalary >= (loanamount*.5)))

because

string currentjob will have different has code and the string "yes" will have diffrent has code.

In java, == operator checks the hascode values of the strings when comparing but not the equailty of the strings.

In order to make it work properly, we need to compare the strings with equals() method on the string liter "yes".

This condtion does work properly:

else if(("yes".equals(currentjob)) && (annualsalary >= (loanamount*.5)))