This project is a basic Java application designed to manage attendance by modeling core entities like Student and Course. It follows an object-oriented programming approach and demonstrates foundational concepts such as class creation, encapsulation, arrays of objects, and use of the this keyword.
- Set up the initial folder structure for the Java project.
- Created the
Main.javafile with a welcome message. - Verified the build process using
javacand executed the app usingjava.
src/com/school/Main.java: Entry point of the program.
- Defined
Studentclass withstudentId,name,setDetails(), anddisplayDetails()method. - Defined
Courseclass withcourseId,courseName,setDetails(), anddisplayDetails()method. - Utilized arrays of objects in
Main.javato manage and display multiple students and courses. - Introduced basic usage of
thiskeyword.
- Implemented parameterized constructors in
StudentandCourseclasses for object initialization. - Utilized
private staticmember variables for automatic and unique ID generation. - Demonstrated the use of the
thiskeyword to distinguish instance variables from constructor parameters. - Changed
Course'scourseIdtointfor simpler auto-generation and updated its display. - Updated
Main.javato use constructors and show ID progression.
- Applied encapsulation to
StudentandCourseclasses by making fieldsprivateand adding publicgetters. - Introduced a new
AttendanceRecordclass withprivatefields, a constructor, andgettersto store attendance data. - Implemented basic validation in the
AttendanceRecordconstructor for the attendance status (allowing only "Present" or "Absent"). - Used an
ArrayListinMain.javato store and displayAttendanceRecordobjects. - Demonstrated retrieving IDs using getters (e.g.,
student1.getStudentId()) when creating records.
- Created a base class
Person.javawith common attributes (id,name), a universal auto-ID generator, and adisplayDetails()method. - Modified
Student.javato inherit fromPerson, usingsuper()to call the parent constructor and overridingdisplayDetails()to add student-specific info (e.g., grade level). - Created
Teacher.javaextendingPerson, adding asubjectTaughtattribute and its owndisplayDetails(). - Created
Staff.javaextendingPerson, adding aroleattribute and its owndisplayDetails(). - Demonstrated creation and display of
Student,Teacher, andStaffobjects inMain.java. - Updated
AttendanceRecordcreation to use the inheritedgetId()method.
- Defined a
Storableinterface with atoDataString()method. - Modified
Student,Course, andAttendanceRecordclasses to implement theStorableinterface and provide their specifictoDataString()implementations (CSV format). - Created a
FileStorageServiceclass with asaveData(List<? extends Storable> items, String filename)method to writeStorableobjects to a text file. - Utilized
try-with-resourcesfor safe file handling (PrintWriter,FileWriter). - Demonstrated in
Main.javahow to save lists of students, courses, and attendance records to separate files (students.txt,courses.txt,attendance_log.txt). - Discussed the flexibility provided by interfaces for handling different types of storable objects uniformly.
- Modified
AttendanceRecordto holdStudentandCourseobjects instead of just their IDs, enhancing its object-oriented nature and how records are displayed. ThetoDataString()method still uses IDs for simpler file storage. - Created a
displaySchoolDirectory(List<Person> people)method inMain.javato demonstrate polymorphism. This method iterates through a list ofPersonobjects (containingStudent,Teacher,Staffinstances) and callsperson.displayDetails(). The correct overridden method for each specific object type is executed at runtime. - Populated a
List<Person>inmainand used it withdisplaySchoolDirectory. - Updated
Main.javato useinstanceofand casting when preparing the list of students for saving, asPersonitself does not implementStorable. - Discussed how polymorphism allows for flexible and extensible code by treating different object types uniformly through a common interface or base class reference.
- Created an
AttendanceService.javaclass to encapsulate attendance logic and manage the list ofAttendanceRecordobjects. - Implemented overloaded
markAttendancemethods inAttendanceService:markAttendance(Student student, Course course, String status)markAttendance(int studentId, int courseId, String status, List<Student> allStudents, List<Course> allCourses)(performs lookups)
- Implemented overloaded
displayAttendanceLogmethods inAttendanceService:displayAttendanceLog()(shows all records)displayAttendanceLog(Student student)(filters by student)displayAttendanceLog(Course course)(filters by course)
- Utilized Java Streams for filtering records in the specific display methods.
AttendanceServicenow usesFileStorageServiceto save itsattendanceLog.- Demonstrated the use of these overloaded methods in
Main.java, showing how different method signatures allow for flexible ways to call the same conceptual operation.
- Applied the Single Responsibility Principle (SRP) by creating dedicated service classes.
- Created
RegistrationService.javato handle the registration, management (lists, lookups), and saving ofStudent,Teacher,Staff, andCourseentities. - Modified
Teacher.javaandStaff.javato implementStorablefor file persistence. - Refactored
AttendanceService.java:- It now depends on
RegistrationServicefor looking up students/courses by ID. - Removed internal lookup helper methods, delegating this to
RegistrationService. - Its primary focus is now solely on managing attendance records.
- It now depends on
- Updated
Main.javato act as an orchestrator, instantiating and using these services. Direct entity list management was removed fromMain. - Demonstrated improved code organization and clearer separation of concerns.
- Navigate to the project root directory.
- Compile:
javac src/com/school/*.java - Run:
java -cp src com.school.Main - Check for
students.txt,teachers.txt,staff.txt,courses.txt, andattendance_log.txt.
- Added a
capacityfeature to theCourseclass, along with an internal list ofenrolledStudents. - Updated
Course.displayDetails()to show capacity and enrollment count, andCourse.toDataString()to save capacity. - Modified
RegistrationService:createCoursemethod now accepts a capacity parameter.- Added
enrollStudentInCourse(Student student, Course course)method to handle enrollment logic, checking against course capacity.
- Updated
Main.javato demonstrate course creation with capacity, student enrollment attempts (including exceeding capacity), and displaying updated course information. - Discussed how other SOLID principles (like Open-Closed and Dependency Inversion) could be applied for further enhancements and flexibility.
- Concluded the 10-part project, having built a foundational console-based attendance system.
- Navigate to the project root directory.
- Compile:
javac src/com/school/*.java - Run:
java -cp src com.school.Main - Check
courses.txtfor the capacity field and other files for their respective data.