// Class to represent a student
class Student {
private String studentId;
private String name;
private String familyDetails;
public Student(String studentId, String name, String familyDetails) {
this.studentId = studentId;
this.name = name;
this.familyDetails = familyDetails;
}
public String getStudentId() {
return studentId;
}
public String getName() {
return name;
}
public String getFamilyDetails() {
return familyDetails;
}
}
// Class to manage student records
class StudentRecords {
private Map<String, Student> students; // Map to store students
public StudentRecords() {
this.students = new HashMap<>();
// Initialize with some sample data
students.put("1001", new Student("1001", "Alice", "Parents: John Doe and Jane Doe"));
students.put("1002", new Student("1002", "Bob", "Parents: Mike Smith and Sarah Smith"));
}
public Student getStudentById(String studentId) {
return students.get(studentId);
}
}
// Class to manage user authentication
class AuthenticationManager {
private Map<String, String> credentials; // Map to store username -> password
public AuthenticationManager() {
this.credentials = new HashMap<>();
// Initialize with some sample credentials (in a real system, passwords should be hashed)
credentials.put("user1", "password1");
credentials.put("user2", "password2");
}
public boolean authenticate(String username, String password) {
// Check if the username exists and the password matches
return credentials.containsKey(username) && credentials.get(username).equals(password);
}
}
// Main class to run the program
public class StudentManagementSystem {
public static void main(String[] args) {
AuthenticationManager authManager = new AuthenticationManager();
StudentRecords studentRecords = new StudentRecords();
Scanner scanner = new Scanner(System.in);
// Login loop
boolean loggedIn = false;
String username, password;
do {
System.out.print("Enter username: ");
username = scanner.nextLine();
System.out.print("Enter password: ");
password = scanner.nextLine();
loggedIn = authManager.authenticate(username, password);
if (!loggedIn) {
System.out.println("Invalid username or password. Please try again.");
}
} while (!loggedIn);
System.out.println("Login successful!");
// Once logged in, provide access to student records
System.out.println("Welcome to Student Management System");
// Example: Retrieve and display student details
String studentId = "1001"; // Example student ID
Student student = studentRecords.getStudentById(studentId);
if (student != null) {
System.out.println("Student ID: " + student.getStudentId());
System.out.println("Student Name: " + student.getName());
System.out.println("Family Details: " + student.getFamilyDetails());
} else {
System.out.println("Student not found!");
}
// Close scanner
scanner.close();
}
import java.util.HashMap; import java.util.Map; import java.util.Scanner;
// Class to represent a student class Student { private String studentId; private String name; private String familyDetails;
}
// Class to manage student records class StudentRecords { private Map<String, Student> students; // Map to store students
}
// Class to manage user authentication class AuthenticationManager { private Map<String, String> credentials; // Map to store username -> password
}
// Main class to run the program public class StudentManagementSystem {
}