Java Bootcamp – Workbooks and Challenges
)}

Debugging Exercise 2

Goal: debug the Conditionals.java code.

From Java Bootcamp Resources -> Module 2 -> 8\. Exception Handling -> Debugging Workbooks open the folder, exercise-two.

If you can't find it, please download the updated resources from Github.

Prerequisite: Conditional Assignment


You can conditionally assign a value using the operators: ? and :.

variable = (comparison) ? (value1) : (value2)
  • If the comparison is true, the variable equals value1.

  • If the comparison is false, the variable equals value2.

The conditional assignment syntax is a more concise way to write:

if (comparison) { variable = value1 } else { variable = value2 }

Debugging


You can only apply for a mortgage if you're over 18 and have a good credit score (debt = 0). The user is 24 and carries a debt of 4000. Yet, the code outputs:

>>: We're processing your application

Use breakpoints to:

  • Visualize the runtime.

  • Debug the program line by line.

Run test cases.

After you debug the program, run the following test cases:

int age = 16; double debt = 4000;

>>: You cannot apply

int age = 16; double debt = 0;

>>: You cannot apply

int age = 24; double debt = 0;

>>: We're processing your application

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.