-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAdmin.java
More file actions
89 lines (72 loc) · 2.14 KB
/
Copy pathAdmin.java
File metadata and controls
89 lines (72 loc) · 2.14 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.util.ArrayList;
public class Admin extends LibraryUser implements AdminInterface{
public int addUser(String userName, String password, int type){
Library lib = Library.getInstance("LUMS");
if(lib.findUser(userName) != null){
System.out.println("This username already exists! Choose Another one.");
return -1;
}
int result = -1;
if(type == Constants.ADMIN){
Admin admin = new Admin(userName,password,type,false);
result = admin.userID;
lib.users.add(admin);
}
else if(type == Constants.STUDENT){
Student student = new Student(userName,password);
student.userID = Library.nextUserID;
Library.nextUserID++;
result = student.userID;
lib.users.add(student);
}
else if(type == Constants.FACULTY){
Faculty faculty = new Faculty(userName,password);
faculty.userID = Library.nextUserID;
Library.nextUserID++;
result = faculty.userID;
lib.users.add(faculty);
}
return result;
}
public boolean removeUser(int userID){
Library lib = Library.getInstance("LUMS Library");
LibraryUser user = lib.findUser(userID);
if(user == null){
return false;
}
// Remove the user!
return lib.removeUser(userID);
}
public int addResource(String name, int type){
Library lib = Library.getInstance("LUMS Library");
int result = -1;
if(type == Constants.BOOK){
Book book = new Book(name,Library.nextResID);
lib.resources.add(book);
result = book.resourceID;
}
else if(type == Constants.COURSE_PACK){
CoursePack pack = new CoursePack(name,Library.nextResID);
lib.resources.add(pack);
result = pack.resourceID;
}
else if(type == Constants.MAGAZINE){
Magazine mag = new Magazine(name,Library.nextResID);
lib.resources.add(mag);
result = mag.resourceID;
}
Library.nextResID++;
return result;
}
public boolean removeResource(int resourceID){
Library lib = Library.getInstance("LUMS Library");
return lib.removeResource(resourceID);
}
Admin(String user,String pass, int typ,boolean firstInstance){
this.userName = user;
this.password = pass;
this.type = typ;
this.userID = Library.nextUserID;
Library.nextUserID++;
}
}