Java Bootcamp – Workbooks and Challenges
)}

Workbook 3.7

From Java Bootcamp Resources -> Module 1 -> 3. Booleans and Conditionals, open Workbook 3.7.

The Royal Bank of Java


In this workbook, you work for the Royal Bank of Java. Your job is to approve customers for a loan if they:

  • Have $10,000 in their savings account.

  • Have less than $5,000 in credit card debt.

  • Have worked for more than 2 years.

The user will also need to provide their name.

Your task is to scan for values and use if-else to control how these statements print.

public class Bank { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("\n****ROYAL BANK OF JAVA****"); System.out.println("Are you here to get a mortgage? (yes or no)"); System.out.println("\nGreat! In one line" + "\nHow much money do you have in your savings?" + "\nAnd, how much do you owe in credit card debt?"); System.out.println("\nHow many years have you worked for?"); System.out.println("What is your name?"); System.out.println("Congratulations <name>, you have been approved!"); System.out.println("Sorry, you are not eligible for a mortgage"); System.out.println("\nOK. Have a nice day!"); scan.close(); } }

Task 1 - Pick up the user's decision


The code starts by asking the user if they're here to get a mortgage. Use Scanner to pick up their decision.

System.out.println("\n****ROYAL BANK OF JAVA****"); System.out.println("Are you here to get a mortgage? (yes or no)"); //Task 1 - Pick up the user's decision.

Task 2 - if - else


If the decision is 'yes', ask the user about their savings and debt. If the decision is anything other than 'yes', print: 'OK. Have a nice day!'.

   //Task 2
 -- Print this if the decision is "yes"
         System.out.println("\nGreat! In one line" +
            "\nHow much money do you have in your savings?" +
            "\nAnd, how much do you owe in credit card debt?");

 -- Print this if the decision is not "yes"
          System.out.println("\nOK. Have a nice day!");

Output for yes:

Output for else:

Task 3 - Pick up the savings and debt values


Pick up and store the savings and debt values.

System.out.println("\nGreat! In one line" + "\nHow much money do you have in your savings?" + "\nAnd, how much do you owe in credit card debt?"); // Task 3 - Pick up each value

Task 4 - Pick up the number of years


Task 5 - Pick up the user's name


Careful not to fall into the nextLine() trap.

Task 6 - Logical Operator


Use a logical operator to check if the user has

  • $10,000 in their savings account.

  • less than $5,000 in credit card debt.

  • 2 years of work experience.

If they meet the requirements, print:

Congratulations <name>, you have been approved!

Otherwise, print:

Sorry, you are not eligible for a mortgage.

Finally, use these values:

  • savings: 20000

  • debt: 1500

  • years: 7

Final Ouput:

Good Luck!


Feedback Summary
4.8
39 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.