Workbook 3.7
From the Java Bootcamp Resources
, launch the Workbook 3.7
folder.
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 at least $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
-
at least $10,000 in their savings account.
-
less than $5,000 in credit card debt.
-
more than 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:
Visualizing the Runtime
After you solve this workbook, I still recommend watching the video solution on Udemy.
It will show you how to visualize the runtime using Visual Studio Code.