14 09 Projet

This lesson puts everything we have learned about files into practice with a small project. The goal is to list students grouped by field of study and persist the whole thing in a single text file. We will build two simple classes and then orchestrate them from main.

The first class is Student. It carries an id, a name and a field id. The student id is incremented automatically through a static counter, and the field id is filled in later, when each student is attached to a field. The second class is Field (the academic track), which exposes its own auto-incremented id and a name.

Building the data in main

  • Declare an array of three Field instances representing the available tracks.
  • Declare an array of five Student instances.
  • Assign each student to one of the fields so the link is materialized.
  • Create the destination text file using FileWriter as in the previous lesson.
  • Write the fields and the students one after the other so the file groups them together.

By the end of the video you have a working mini-application that builds objects in memory, ties them together and writes their content to disk. This is also a good moment to revisit object-oriented basics: each entity is a class with its own state, and the file is the persistent representation of that state. The next lesson reads the same file back to display the data.

Summary

This lesson covers a practical Java project that creates a Student class with auto-incrementing ID and name fields. The project involves managing collections of majors and students using arrays (3 majors and 5 students), and storing this data in a file for persistent use throughout the course.

Key points

  • Create a Student class containing an auto-incremented ID field and a name field
  • Initialize arrays to hold multiple instances: one array for 3 majors and one array for 5 students
  • The Student ID automatically increments for each new instance created
  • Design the project to read and write student and major data to a file for persistent storage

FAQ

What fields does the Student class contain?

The Student class contains an auto-incremented ID field and a name field. The ID automatically increments each time a new student instance is created.

How many students and majors will the project handle?

The project uses an array containing 5 student instances and an array containing 3 major/specialty instances.

Why is file storage important in this project?

The file is created to persistently store the student and major data, allowing this information to be reused and referenced throughout the course.