|
@ -188,25 +188,23 @@ public class Administration { |
|
|
{ |
|
|
{ |
|
|
//the entered id is used |
|
|
//the entered id is used |
|
|
System.out.println("Please enter an ID which is not being 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) |
|
|
else if(findProfessorById(UserId) == null || findAdminById(UserId) == null || findStudentById(UserId) == null) |
|
|
{ |
|
|
{ |
|
|
//the entered id is not used |
|
|
//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)) |
|
|
if(!rightPrefix(UserId, userType)) |
|
|
{ |
|
|
{ |
|
|
//the prefix is wrong |
|
|
//the prefix is wrong |
|
|
correctData = false; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else if(!isNumber(substring)) |
|
|
|
|
|
|
|
|
else if(!isNumber(UserId)) |
|
|
{ |
|
|
{ |
|
|
//the substring does not contain only digits |
|
|
//the substring does not contain only digits |
|
|
System.out.println("Every character besides the first one need to be digits"); |
|
|
System.out.println("Every character besides the first one need to be digits"); |
|
|
correctData = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else{ |
|
|
else{ |
|
@ -238,15 +236,18 @@ public class Administration { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
|
* @param substring the userID without the prefixes S (for Student ), A ( Admin), P (Professor) |
|
|
|
|
|
|
|
|
* @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 |
|
|
* @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) |
|
|
|
|
|
|
|
|
public boolean isNumber(String userId) |
|
|
{ |
|
|
{ |
|
|
if(substring == null || substring.isEmpty()) |
|
|
|
|
|
{ |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//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()) |
|
|
for(char c : substring.toCharArray()) |
|
|
{ |
|
|
{ |
|
|
if(!Character.isDigit(c)) |
|
|
if(!Character.isDigit(c)) |
|
@ -267,53 +268,50 @@ public class Administration { |
|
|
{ |
|
|
{ |
|
|
switch (i){ |
|
|
switch (i){ |
|
|
case 1: //Student |
|
|
case 1: //Student |
|
|
if(userId.startsWith("S")) |
|
|
|
|
|
|
|
|
if(!userId.startsWith("S")) |
|
|
{ |
|
|
{ |
|
|
return true; |
|
|
|
|
|
|
|
|
System.out.println("The ID needs to start with a capital S!"); |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
else if(userId.startsWith("s")) |
|
|
else if(userId.startsWith("s")) |
|
|
{ |
|
|
{ |
|
|
System.out.println("The ID needs to start with a capital S!"); |
|
|
System.out.println("The ID needs to start with a capital S!"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
else if(!userId.startsWith("S")) |
|
|
|
|
|
|
|
|
else |
|
|
{ |
|
|
{ |
|
|
System.out.println("The ID needs to start with a capital S!"); |
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
break; |
|
|
|
|
|
case 2: //Admin |
|
|
|
|
|
if(userId.startsWith("A")) |
|
|
|
|
|
|
|
|
case 2: //Admin |
|
|
|
|
|
if(!userId.startsWith("A")) |
|
|
{ |
|
|
{ |
|
|
return true; |
|
|
|
|
|
|
|
|
System.out.println("The ID needs to start with a capital A!"); |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
else if(userId.startsWith("a")) |
|
|
else if(userId.startsWith("a")) |
|
|
{ |
|
|
{ |
|
|
System.out.println("The ID needs to start with a capital A!"); |
|
|
System.out.println("The ID needs to start with a capital A!"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
else if(!userId.startsWith("A")) |
|
|
|
|
|
|
|
|
else |
|
|
{ |
|
|
{ |
|
|
System.out.println("The ID needs to start with a capital A!"); |
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
break; |
|
|
|
|
|
case 3: //Professor |
|
|
case 3: //Professor |
|
|
if(userId.startsWith("P")) |
|
|
|
|
|
|
|
|
if(!userId.startsWith("P")) |
|
|
{ |
|
|
{ |
|
|
return true; |
|
|
|
|
|
|
|
|
System.out.println("The ID needs to start with a capital P!"); |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
else if(userId.startsWith("p")) |
|
|
else if(userId.startsWith("p")) |
|
|
{ |
|
|
{ |
|
|
System.out.println("The ID needs to start with a capital P!"); |
|
|
System.out.println("The ID needs to start with a capital P!"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
else if(!userId.startsWith("P")) |
|
|
|
|
|
|
|
|
else |
|
|
{ |
|
|
{ |
|
|
System.out.println("The ID needs to start with a capital P!"); |
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: //Error |
|
|
default: //Error |
|
|
System.out.println("Error"); |
|
|
System.out.println("Error"); |
|
|