Java Bootcamp – Workbooks and Challenges
)}

Workbook – Part 3

Prerequisite: you finished writing the code for Part 2.

Task 1 – Make your fields private


You should not have direct access to fields. Make every field in the Person class private.

Task 2 – Add four getters


The Person class has five fields. But for now, we will ignore the passport field.

Add getters for name, nationality, dateOfBirth, and seatNumber.

Task 3 – Call the getters


  • Call the getters from your println function. Each getter returns a copy of the field's value.

  • Re-run the code

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

Task 4 – Add four setters


Add setters for name, nationality, dateOfBirth, and seatNumber.

Task 5 – Call a setter


The person's current seat number is already taken. But, seat 10 is available. Using a setter, update the person's seat number to 10.

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

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.