Java Bootcamp – Workbooks and Challenges
)}

Workbook 7.6

From the Java Bootcamp Resources, launch Workbook 7.6.

6.png

Task 1

Your constructor will not receive a passport parameter.

public Person(String name, String nationality, String dateOfBirth, int seatNumber) { // ... }

But it must set passport equal to an array that stores 3 elements.

public Person(String name, String nationality, String dateOfBirth, int seatNumber) { // ... this.passport = new String[3]; }

We do this because we cannot update their passport until they apply for it.

Task 2

Add the getter getPassport(). Make sure it returns a copy of the array.

Task 3

Add this println() function at the end of your main() method. Replace the placeholders where appropriate.

System.out.println("Name: " + <name field> + "\n" + "Nationality: " + <nationality field > + "\n" + "Date of Birth: " + <birth date field> + "\n" + "Seat Number: " + <seat field> + "\n" + "Passport: " + <toString of passport field> + "\n");

Your output should appear as follows:

>>: Name: Rayan Slim >>: Nationality: Canadian >>: Date of Birth: 01/01/1111 >>: Seat Number: 5 >>: Passport: [null, null, null]

Task 4

Your code contains a setter setPassport. Notice that it doesn't have a parameter.

public void setPassport() { }

Inside setPassport, set passport equal to {name, nationality, dateOfBirth}.

Task 5

Call the setter if the person gets approved for a passport.

Test Case: Passport Approved.

>>: Name: Rayan Slim >>: Nationality: Canadian >>: Date of Birth: 01/01/1111 >>: Seat Number: 5 >>: Passport: [Rayan Slim, Canadian, 01/01/1111]

Test Case: Passport Denied.

>>: Name: Rayan Slim >>: Nationality: Canadian >>: Date of Birth: 01/01/1111 >>: Seat Number: 5 >>: Passport: [null, null, null]

Keep running your code and make sure you get alternating outputs.

Visualizing the Runtime

After you solve this workbook, I still recommend watching the video solution on Udemy.

6.png

It will show you how to visualize the runtime using Visual Studio Code.


Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer

Feedback Summary
4.7
43 students
5

91%
4

2%
3

0%
2

0%
1

7%
Written Reviews
There are no written reviews yet.