Java Bootcamp – Workbooks and Challenges
)}

Workbook 7.1

Inside the Java Bootcamp Resources, launch Workbook 7.1.

1.png

Task 1

Create a new file named Person.java. Inside the file, create the Person class.

public class Person { }

The Person class will define the following fields:

    String name;
    String nationality;
    String dateOfBirth;
    String[] passport;
    int seatNumber;

The Person class is a blueprint from which you can create Person objects.

Task 2

Create one object of the Person class. Then print every field in the object.

>>: null >>: null >>: null >>: null >>: 0

Task 3

Update each field in the object before printing them.

person.name = // a String person.nationality // a String person.dateOfBirth = // a String person.passport = // Array that stores: {person.name, person.nationality, person.dateOfBirth} person.seatNumber = // an Integer

Hint for passport

You can only use shorthand initialization in the same line as the variable declaration.

0.png

That's because the compiler is able to infer the array type.

12.png

You cannot use shorthand initialization on another line because the compiler can't infer the type.

13.png

You need to explicitly define a new array that can store String elements.

14.png

Task 4

Print the fields of your updated object.

System.out.println(person.name); System.out.println(person.nationality); System.out.println(person.dateOfBirth); System.out.println(Arrays.toString(person.passport)); System.out.println(person.seatNumber);

Result

>>: Rayan Slim
>>: Canadian
>>: 01/01/1111
>>: [Rayan Slim, Canadian, 01/01/1111]
>>: 5

Visualizing the Runtime

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

1.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.