You are on page 1of 2

Implement data validation in the Student class:

java
Download
Copy code
public class Student {
// Other code remains the same

public void setStudentNo(String studentNo) {


if (studentNo == null || studentNo.isEmpty()) {
throw new IllegalArgumentException("Student number cannot be null or
empty");
}
this.studentNo = studentNo;
}

// Similarly, add validation for other fields


}
Add exception handling to the Library class:
java
Download
Copy code
public class Library {
// Other code remains the same

public void loadStudentsFromFile(String fileName) {


try (BufferedReader reader = new BufferedReader(new FileReader(fileName)))
{
String line;
while ((line = reader.readLine()) != null) {
String[] studentDetails = line.split(",");
// Assuming correct data format and splitting based on ","
// Parse and add each student details to the list
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Failed to load students from file: " + fileName);
}
}
}
Consider using a database system like SQLite for more efficient data storage. You
can use JDBC to interact with the database in Java.

Add a toString method in the Student class to provide a better representation of


the student object when printed:

java
Download
Copy code
public class Student {
// Other code remains the same

@Override
public String toString() {
return "Student [studentNo=" + studentNo + ", surname=" + surname + ",
firstName=" + firstName + ", middleName=" + middleName + ", college=" + college +
", department=" + department + ", level=" + level + ", phoneNumber=" + phoneNumber
+ ", gender=" + gender + "]";
}
}
Consider implementing a user interface using JavaFX or Swing for easier interaction
with the application.

You might also like