From 8dd3285cbba5638065bc171caba799d689cb4af0 Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Wed, 7 Feb 2024 10:38:04 +0100 Subject: [PATCH] Added exception handling for registerUser Method --- src/main/java/org/example/Administration.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index a27384c..14b2ae9 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -185,8 +185,23 @@ public class Administration { } else if(findProfessorById(UserId) == null || findAdminById(UserId) == null || findStudentById(UserId) == null) { - System.out.println("The Id has not been used already!"); - correctData = true; + String substring = UserId.substring(1); + + if(!rightPrefix(UserId, userType)) + { + correctData = false; + } + else if(!isNumber(substring)) + { + System.out.println("Every character besides the first one need to be digits"); + correctData = false; + + } + else{ + System.out.println("The Id has not been used already!"); + correctData = true; + } + } switch (userType)