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
Fieldinstances representing the available tracks. - Declare an array of five
Studentinstances. - Assign each student to one of the fields so the link is materialized.
- Create the destination text file using
FileWriteras 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.