Browse Source

Added basic registerUser Method to Administration Class

remotes/origin/fdai7780
Tobias Herbert 11 months ago
parent
commit
b84b57d40b
  1. 50
      src/main/java/org/example/Administration.java

50
src/main/java/org/example/Administration.java

@ -2,6 +2,7 @@ package org.example;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Administration {
/**
@ -10,6 +11,7 @@ public class Administration {
private List<Professor> professors;
private List<Admin> admins;
private List<Student> students;
Scanner scanner = new Scanner(System.in);
/**
* Constructor
@ -158,6 +160,54 @@ public class Administration {
return null;
}
public void registerUser()
{
String UserId = null;
String UserName = null;
System.out.println("Enter the type of user (1-Student, 2-Admin, 3-Professor): ");
int userType = scanner.nextInt();
boolean correctData = false;
while(!correctData)
{
System.out.println("Enter the User Details!");
System.out.println("Name: ");
UserName = scanner.next();
System.out.println("ID: ");
UserId = scanner.next();
if(findProfessorById(UserId) != null || findAdminById(UserId) != null || findStudentById(UserId) != null)
{
System.out.println("Please enter an ID which is not being used!");
correctData = false;
}
else if(findProfessorById(UserId) == null || findAdminById(UserId) == null || findStudentById(UserId) == null)
{
System.out.println("The Id has not been used already!");
correctData = true;
}
switch (userType)
{
case 1:
Student student = new Student(UserName, UserId, "Student");
addStudents(student);
break;
case 2:
Admin admin = new Admin(UserName, UserId, "Admin");
addAdmin(admin);
break;
case 3:
Professor professor = new Professor(UserId, UserName, "Professor");
addProfessor(professor);
default:
break;
}
}
}
}
Loading…
Cancel
Save