From b84b57d40bbbfcf5e257efb467f81c94bf7352ea Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Wed, 7 Feb 2024 09:42:26 +0100 Subject: [PATCH] Added basic registerUser Method to Administration Class --- src/main/java/org/example/Administration.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 2be870c..4e4c4f7 100644 --- a/src/main/java/org/example/Administration.java +++ b/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 professors; private List admins; private List 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; + } + } + } + }