-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRegistrar.java
46 lines (44 loc) · 1.55 KB
/
Registrar.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Iterator;
import java.util.Random;
import java.util.Set;
public class Registrar extends User{
public Registrar(String firstName, String lastName, String userName, String password, Set<Registrar> allRegistrars){
Random rand = new Random();
boolean uniqueLoop = true;
int tries = 0;
int tempId =-1;
while(uniqueLoop && tries < 100){
tempId = rand.nextInt((86666666 - 83333333) + 1) + 83333333;
boolean match = false;
tries++;
Iterator<Registrar> it = allRegistrars.iterator();
while(it.hasNext()){
Registrar current = it.next();
if(current.firstName == firstName && current.lastName == lastName){
setID(-1);
return;
}
if(current.getID() == tempId)
match = true;
if(match)
uniqueLoop = true;
else
uniqueLoop = false;
}
}
setID(tempId);
this.firstName = firstName;
this.lastName = lastName;
setUserName(userName);
setPassword(password);
}
public void addNewCourse(String name, String department, Professor teacher, int waitingListCap, int studentCap, int hours, Set<Course> allCourses){
allCourses.add(new Course(name, department, teacher, waitingListCap, studentCap, hours, allCourses));
}
public void registerStudentClasses(Student toBeAdded, Course courseToAdd){
toBeAdded.currentCourses.add(courseToAdd);
}
public void registerNewStudent(String firstName, String lastName, String userName, String password, Set<Student> allStudents){
allStudents.add(new Student(firstName, lastName, userName, password, allStudents));
}
}