Java Bootcamp – Workbooks and Challenges
)}

Workbook – Part 5

Prerequisite: you finished writing the code for Part 4.

Based on the requirements, a person can perform two actions. They can:

  1. Apply for a passport.

  2. Choose a seat on the plane.

Task 1 – apply for a passport


Inside the Person class, define the applyPassport function.

/** * Function name: applyPassport * @return (boolean) * * Inside the function: * 1. Returns a random boolean of true or false. */

It must return a random boolean. The boolean determines if a person qualifies for a passport.

Task 2 – choosing a seat


Inside the Person class, define the chooseSeat function.

/** * Function name: chooseSeat * * Inside the function: * 1. Sets this.seat to a random number between 1 -- 11. */

Task 3 – Test the applyPassport action.


If you followed every step from Part 1 to Part 4, your main() method defines two objects.

  • Remove the second object.

  • Call applyPassport from the first object. If the return value is true:

    • print: Congratulations <person.getName()>. Your passport was approved!
  • Otherwise:

    • print: We're sorry <person.getName()>. We cannot process your application."

Example output 1:

>>: Name: Rayan Slim >>: Nationality: Canadian >>: Date of Birth: 01/01/1111 >>: Seat Number: 10 >>: Congratulations Rayan Slim. Your passport was approved!

Example output 2:

>>: Name: Rayan Slim
>>: Nationality: Canadian
>>: Date of Birth: 01/01/1111
>>: Seat Number: 10

>>: We're sorry Rayan Slim. We cannot process your application.

Run your code multiple times. Each run should output a random result.

Task 4 – Test the chooseSeat action.


The chooseSeat action is useful if the person's seat is already taken. In which case, the person can "choose another seat".

For now, we need to make sure that it works. Remove any calls to the setter: setSeat. Instead, call the chooseSeat action.

Example output 1

>>: Name: Rayan Slim >>: Nationality: Canadian >>: Date of Birth: 01/01/1111 >>: Seat Number: 10 >>: Congratulations Rayan Slim. Your passport was approved!

Example output 2

>>: Name: Rayan Slim
>>: Nationality: Canadian
>>: Date of Birth: 01/01/1111
>>: Seat Number: 6

>>: We're sorry Rayan Slim. We cannot process your application.

Example output 3

>>: Name: Rayan Slim >>: Nationality: Canadian >>: Date of Birth: 01/01/1111 >>: Seat Number: 4 >>: Congratulations Rayan Slim. Your passport was approved!

Keep testing the action. It should keep updating the person's seatNumber to a random int between 1–11.

Good Luck!


Feedback Summary
4.8
38 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.