File Based System
File Based System
A Java-based Student Management System that utilizes file storage for data persistence instead
of a traditional database. This system enables basic academic operations such as managing
students, lecturers, courses, programmes, and student results using object-oriented principles.
https://github.com/DRAVIS55/JAVA-STUDENT-IMPLEMENTATION-FILE-BASED
MEMBERS
Table of Contents
APP.java ...................................................................................................................................... 2
Course.java ................................................................................................................................. 5
Lecture.java .............................................................................................................................. 12
Person ....................................................................................................................................... 17
Programme.java ....................................................................................................................... 20
Student.java.............................................................................................................................. 27
SystemGUI.java......................................................................................................................... 35
1
APP.java
import java.io.File;
import java.io.IOException;
checkAndCreateFile(fileName);
if (!file.exists()) {
if (file.createNewFile()) {
} else {
2
} else {
if (!file.canRead() || !file.canWrite()) {
try {
} else {
} catch (SecurityException e) {
e.printStackTrace();
if (!file.canRead() || !file.canWrite()) {
} else {
3
System.out.println("Failed to delete and recreate the file: " + file.getName());
4
Course.java
import java.io.*;
import java.util.ArrayList;
String line;
if (line.contains(courseCode)) {
courseExists = true;
break;
if (courseExists) {
return;
5
// If course doesn't exist, add it to the file
writer.write(courseData);
writer.newLine();
} catch (IOException e) {
e.printStackTrace();
try {
String line;
if (data[0].equals(courseCode)) {
6
courseFound = true;
fileContent.add(line);
reader.close();
if (!courseFound) {
return;
writer.write(content);
writer.newLine();
} catch (IOException e) {
e.printStackTrace();
7
public void deleteCourse(String courseCode) {
try {
String line;
if (data[0].equals(courseCode)) {
courseFound = true;
continue;
fileContent.add(line);
reader.close();
if (!courseFound) {
return;
writer.write(content);
writer.newLine();
8
}
} catch (IOException e) {
e.printStackTrace();
String line;
} catch (IOException e) {
e.printStackTrace();
return contentList;
9
// Search for students registered in a specific course
String line;
if (data[1].equals(courseId)) {
studentsFound = true;
if (!studentsFound) {
} catch (IOException e) {
e.printStackTrace();
return students;
10
public ArrayList<String[]> getLecturersByCourse(String courseId) {
String line;
if (data[1].equals(courseId)) {
lecturersFound = true;
if (!lecturersFound) {
} catch (IOException e) {
e.printStackTrace();
return lecturers;
11
Lecture.java
import java.io.*;
import java.util.ArrayList;
public boolean registerLecturer(String lecturerID, String f_name, String s_name, String phone,
String department, String email) {
writer.newLine();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
12
// Update Lecturer Details
String line;
if (details[0].equals(lecturerID)) {
details[1] = newName;
details[5] = newEmail;
updated = true;
content.append(line).append("\n");
if (updated) {
writer.write(content.toString());
return updated;
} catch (IOException e) {
e.printStackTrace();
13
return false;
String line;
if (details[0].equals(lecturerIdNo)) {
lecturerFound = true;
break;
if (lecturerFound) {
writer.newLine();
return true;
14
} else {
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
String line;
if (details[0].equals(lecturerID)) {
return lecturerDetails;
15
}
} catch (IOException e) {
e.printStackTrace();
return lecturerDetails;
16
Person
public class Person {
// Fields (attributes)
private String id; // This could be a student ID, employee ID, etc.
// Default constructor
public Person() {
this.firstName = "";
this.lastName = "";
this.id = "";
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
return firstName;
17
}
this.firstName = firstName;
return lastName;
this.lastName = lastName;
return id;
this.id = id;
@Override
18
public String toString() {
return "Person [ID=" + id + ", Name=" + firstName + " " + lastName + "]";
19
Programme.java
import java.io.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Scanner;
// Path for the storage files (for simplicity, storing as plain text files)
if (!hasWritePermission(programmeFile)) {
20
new ReusableClass().printMessage("The file is not writable. Please check the file
permissions.");
return;
String line;
while ( reader.hasNextLine()) {
line=reader.nextLine();
if (parts[1].equals(programmeCode)) {
reader.close();
return;
reader.close();
writer.close();
21
new ReusableClass().printMessage("The programme is updated successfully\nProgramme
code: " + programmeCode + "\nProgramme Name: " + programmeName);
if (file.exists()) {
return false;
public void modifyProgram(App app, BigDecimal cost, String code) throws IOException {
String line;
if (parts[1].equals(code)) {
found = true;
22
writer.write(line + "\n");
reader.close();
writer.close();
if (found) {
} else {
tempFile.delete();
String line;
23
while ((line = reader.readLine()) != null) {
if (parts[1].equals(programme_code)) {
continue;
writer.write(line + "\n");
reader.close();
writer.close();
if (found) {
} else {
tempFile.delete();
24
String line;
reader.close();
return;
reader.close();
writer.close();
25
BufferedReader reader = new BufferedReader(new FileReader("students.txt"));
String line;
if (parts[3].equals(programmeId)) {
found = true;
reader.close();
if (!found) {
return students;
26
Student.java
import java.io.*;
import java.util.ArrayList;
// Constructor
public Student() {
public void registerStudent(String firstName, String lastName, String email, String phone,
String gender, String programmeID) {
String line;
if (line.contains(programmeID)) {
27
programmeExists = true;
break;
if (!programmeExists) {
return;
String studentData = firstName + "," + lastName + "," + email + "," + phone + "," +
gender + "," + programmeID;
writer.write(studentData);
writer.newLine();
} catch (IOException e) {
public void enrollStudent(String studentID, String courseCode, String semester, String score) {
28
try {
String line;
if (line.split(",")[0].equals(studentID)) {
studentExists = true;
break;
if (!studentExists) {
return;
if (line.contains(courseCode)) {
courseExists = true;
break;
29
}
if (!courseExists) {
return;
writer.write(enrollmentData);
writer.newLine();
} catch (IOException e) {
try {
30
String line;
line = studentID + "," + courseCode + "," + data[2] + "," + score; // Update score
updated = true;
fileContent.add(line);
if (updated) {
writer.write(content);
writer.newLine();
} else {
} catch (IOException e) {
31
new ReusableClass().printMessage(" Error assigning score!");
String line;
if (data[0].equals(studentID)) {
studentFound = true;
break;
if (!studentFound) {
32
details.add(" Student not found!");
} catch (IOException e) {
return details;
String line;
if (parts[0].equals(studentId)) {
found = true;
33
}
scReader.close();
if (!found) {
return results;
String line;
if (parts[0].equals(courseCode)) {
courseReader.close();
return parts[1];
courseReader.close();
}}
34
SystemGUI.java
import java.io.*;
import java.util.ArrayList;
// Constructor
public Student() {
public void registerStudent(String firstName, String lastName, String email, String phone,
String gender, String programmeID) {
String line;
35
if (line.contains(programmeID)) {
programmeExists = true;
break;
if (!programmeExists) {
return;
String studentData = firstName + "," + lastName + "," + email + "," + phone + "," +
gender + "," + programmeID;
writer.write(studentData);
writer.newLine();
} catch (IOException e) {
36
public void enrollStudent(String studentID, String courseCode, String semester, String score) {
try {
String line;
if (line.split(",")[0].equals(studentID)) {
studentExists = true;
break;
if (!studentExists) {
return;
if (line.contains(courseCode)) {
courseExists = true;
37
break;
if (!courseExists) {
return;
writer.write(enrollmentData);
writer.newLine();
} catch (IOException e) {
try {
38
BufferedReader reader = new BufferedReader(new FileReader("student_courses.txt"));
String line;
line = studentID + "," + courseCode + "," + data[2] + "," + score; // Update score
updated = true;
fileContent.add(line);
if (updated) {
writer.write(content);
writer.newLine();
} else {
39
} catch (IOException e) {
String line;
if (data[0].equals(studentID)) {
studentFound = true;
break;
40
if (!studentFound) {
} catch (IOException e) {
return details;
String line;
if (parts[0].equals(studentId)) {
found = true;
41
}
scReader.close();
if (!found) {
return results;
String line;
if (parts[0].equals(courseCode)) {
courseReader.close();
return parts[1];
courseReader.close();
42
}
43