Objectives
- Familiar with Java text file I/O and object serialization.
In Assignment 2, both the Bachelor and Master of Computer Science course structures are inputted manually inside the main() method. The students enrolment records cannot be kept as well. In Lab 5, you are asked to modify the A2s solution by using the object serialization and file I/O to import/export course objects and export the students enrolment records to a text file.
Tasks:
Task 1:
- Modify the existing Course, Subject and Major classes by implementing the serializable interface;
- Create a new primary class (CreateCourse) without any class field;
- Use the ObjectOutputStream class in the main() method of CreateCourse class to output the Bachelor of Computer Science course object to a binary file named ser (within the same directory as the CreateCourse.java) and the Master of Computer Science course object to a binary file named mcs.ser.You shall re-use the hardcode in A2s solution to create all subject, major and course objects first. Then use the writeObject() method to export the two course objects to two binary files, respectively.
Task 2:
- Update the StudentSystem class in A2s solution (you can use your or my A2 solution) with the exception handling process completed in Lab 4;
- Update the StudentSystem class and use the ObjectInputStream class to import the Bachelor of Computer Science course object and the Master of Computer Science course object from the binary files bcs.ser and ser (created in Task 1), respectively;
- Enrol two students to BCS and MCS course respectively (exactly same process as A2);
- Export all students enrolment record information (the exactly same information displayed on the screen after the completion of the two students enrolment in A2) into a text-file named txt (within the same directory as the StudentSystem.java). You must use the Formatter class and the format() method.
Reviews
There are no reviews yet.