Workbook – Part 2
Prerequisite: you finished writing the code for Part 1.
Create a constructor
Person class has five fields. But, we will ignore the
passport field for now.
So, create a
Person constructor that receives four parameters. Don't include a parameter for
Call the constructor
Remove the field updates from Part 1. Then, use the constructor to update your fields.
Printing each field results in the following output:
>>: Rayan Slim >>: Canadian >>: 01/01/1111 >>: null >>: 5
Print every field as part of one String.
Use the following template:
System.out.println("Name: " + <name field> + "\n" + "Nationality: " + <nationality field> + "\n" + "Date of Birth: " + <birth date field> + "\n" + "Seat Number: " + <seat number field> + "\n");
>>: Name: Rayan Slim >>: Nationality: Canadian >>: Date of Birth: 01/01/1111 >>: Seat Number: 5