Browse Source

documentation: registerUser Method in Administration class

remotes/origin/fdai7780
Tobias Herbert 11 months ago
parent
commit
8694e81cb0
  1. 41
      src/main/java/org/example/Administration.java

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

@ -160,8 +160,13 @@ public class Administration {
return null;
}
/**
* Method to register a User
*/
public void registerUser()
{
//Instance variables
String UserId = null;
String UserName = null;
@ -178,26 +183,34 @@ public class Administration {
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!");
correctData = false;
}
else if(findProfessorById(UserId) == null || findAdminById(UserId) == null || findStudentById(UserId) == null)
{
//the entered id is not used
//creates a substring to check if the id-"syntax" is correct
String substring = UserId.substring(1);
if(!rightPrefix(UserId, userType))
{
//the prefix is wrong
correctData = false;
}
else if(!isNumber(substring))
{
//the substring does not contain only digits
System.out.println("Every character besides the first one need to be digits");
correctData = false;
}
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;
}
@ -206,23 +219,28 @@ public class Administration {
switch (userType)
{
case 1:
case 1: //Student
Student student = new Student(UserName, UserId, "Student");
addStudents(student);
break;
case 2:
case 2: //Admin
Admin admin = new Admin(UserName, UserId, "Admin");
addAdmin(admin);
break;
case 3:
case 3: //Professor
Professor professor = new Professor(UserId, UserName, "Professor");
addProfessor(professor);
default:
default: //Error
break;
}
}
}
/**
*
* @param substring the userID without the prefixes S (for Student ), A ( Admin), P (Professor)
* @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 substring)
{
if(substring == null || substring.isEmpty())
@ -238,10 +256,17 @@ public class Administration {
}
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:
case 1: //Student
if(userId.startsWith("S"))
{
return true;
@ -257,7 +282,7 @@ public class Administration {
return false;
}
break;
case 2:
case 2: //Admin
if(userId.startsWith("A"))
{
return true;
@ -273,7 +298,7 @@ public class Administration {
return false;
}
break;
case 3:
case 3: //Professor
if(userId.startsWith("P"))
{
return true;
@ -290,7 +315,7 @@ public class Administration {
}
break;
default:
default: //Error
System.out.println("Error");
break;
}

Loading…
Cancel
Save