|
@ -2,6 +2,7 @@ package org.example; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Scanner; |
|
|
|
|
|
|
|
|
public class Administration { |
|
|
public class Administration { |
|
|
/** |
|
|
/** |
|
@ -10,6 +11,7 @@ public class Administration { |
|
|
private List<Professor> professors; |
|
|
private List<Professor> professors; |
|
|
private List<Admin> admins; |
|
|
private List<Admin> admins; |
|
|
private List<Student> students; |
|
|
private List<Student> students; |
|
|
|
|
|
Scanner scanner = new Scanner(System.in); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Constructor |
|
|
* Constructor |
|
@ -158,6 +160,166 @@ public class Administration { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Method to register a User |
|
|
|
|
|
*/ |
|
|
|
|
|
public void registerUser() |
|
|
|
|
|
{ |
|
|
|
|
|
//Instance variables |
|
|
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
|
|
//Checks if the entered id is already being used |
|
|
|
|
|
if(findProfessorById(UserId) != null || findAdminById(UserId) != null || findStudentById(UserId) != null) |
|
|
|
|
|
{ |
|
|
|
|
|
//the entered id is used |
|
|
|
|
|
System.out.println("Please enter an ID which is not being used!"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else if(findProfessorById(UserId) == null || findAdminById(UserId) == null || findStudentById(UserId) == null) |
|
|
|
|
|
{ |
|
|
|
|
|
//the entered id is not used |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!rightPrefix(UserId, userType)) |
|
|
|
|
|
{ |
|
|
|
|
|
//the prefix is wrong |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else if(!isNumber(UserId)) |
|
|
|
|
|
{ |
|
|
|
|
|
//the substring does not contain only digits |
|
|
|
|
|
System.out.println("Every character besides the first one need to be digits"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
//the id is not being used and has the right id-"syntax" |
|
|
|
|
|
System.out.println("The Id has not been used already!"); |
|
|
|
|
|
correctData = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (userType) |
|
|
|
|
|
{ |
|
|
|
|
|
case 1: //Student |
|
|
|
|
|
Student student = new Student(UserName, UserId, "Student"); |
|
|
|
|
|
addStudents(student); |
|
|
|
|
|
break; |
|
|
|
|
|
case 2: //Admin |
|
|
|
|
|
Admin admin = new Admin(UserName, UserId, "Admin"); |
|
|
|
|
|
addAdmin(admin); |
|
|
|
|
|
break; |
|
|
|
|
|
case 3: //Professor |
|
|
|
|
|
Professor professor = new Professor(UserId, UserName, "Professor"); |
|
|
|
|
|
addProfessor(professor); |
|
|
|
|
|
default: //Error |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param userId the userID |
|
|
|
|
|
* @return returns true if the substring is only containing digits, returns false either the substring is empty or includes not only digits |
|
|
|
|
|
*/ |
|
|
|
|
|
public boolean isNumber(String userId) |
|
|
|
|
|
{ |
|
|
|
|
|
//creates a substring to check if the id-"syntax" is correct |
|
|
|
|
|
String substring = userId.substring(1); |
|
|
|
|
|
|
|
|
|
|
|
//if(substring == null || substring.isEmpty()) |
|
|
|
|
|
//{ |
|
|
|
|
|
// return false; |
|
|
|
|
|
//} |
|
|
|
|
|
for(char c : substring.toCharArray()) |
|
|
|
|
|
{ |
|
|
|
|
|
if(!Character.isDigit(c)) |
|
|
|
|
|
{ |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param userId the userId to be checked |
|
|
|
|
|
* @param i equals userType |
|
|
|
|
|
* @return returns true if the right prefix is being used |
|
|
|
|
|
*/ |
|
|
|
|
|
public boolean rightPrefix(String userId, int i) |
|
|
|
|
|
{ |
|
|
|
|
|
switch (i){ |
|
|
|
|
|
case 1: //Student |
|
|
|
|
|
if(!userId.startsWith("S")) |
|
|
|
|
|
{ |
|
|
|
|
|
System.out.println("The ID needs to start with a capital S!"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
else if(userId.startsWith("s")) |
|
|
|
|
|
{ |
|
|
|
|
|
System.out.println("The ID needs to start with a capital S!"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
case 2: //Admin |
|
|
|
|
|
if(!userId.startsWith("A")) |
|
|
|
|
|
{ |
|
|
|
|
|
System.out.println("The ID needs to start with a capital A!"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
else if(userId.startsWith("a")) |
|
|
|
|
|
{ |
|
|
|
|
|
System.out.println("The ID needs to start with a capital A!"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
case 3: //Professor |
|
|
|
|
|
if(!userId.startsWith("P")) |
|
|
|
|
|
{ |
|
|
|
|
|
System.out.println("The ID needs to start with a capital P!"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
else if(userId.startsWith("p")) |
|
|
|
|
|
{ |
|
|
|
|
|
System.out.println("The ID needs to start with a capital P!"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
default: //Error |
|
|
|
|
|
System.out.println("Error"); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|