-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrarySystem.java
More file actions
154 lines (120 loc) · 3.49 KB
/
LibrarySystem.java
File metadata and controls
154 lines (120 loc) · 3.49 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package ProgAssignment4;
//Melvin Nguyen 7126782 mnguyen00@umail.ucsb.edu
import java.text.ParseException;
import java.util.ArrayList;
import javax.swing.JFrame;
public class LibrarySystem{
static Database database;
static User currentUser;
static String currentDate;
public static void main(String[] args){
database = new Database();
graphicInterface test = new graphicInterface(database);
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setSize(350,100);
test.setVisible(true);
}
public void setCurrentUser(User x){
currentUser = x;
}
public User getCurrentUser(){
return currentUser;
}
public void setCurrentDate(String x){
currentDate = x;
}
public String getCurrentDate(){
return currentDate;
}
//search books
public ArrayList<String> U1(String input){
ArrayList<Book> catalog = database.getBooks();
ArrayList<Book> results = new ArrayList<Book>();
ArrayList<String> result = new ArrayList<String>();
String [] tempWord = input.split("\\s+");
for(int i = 0; i < tempWord.length; i++){
tempWord[i] = tempWord[i].toLowerCase();
}
for(Book i: catalog){
for(int j = 0; j < (i.getKeywords()).size(); j++){
boolean match = false;
for(int k = 0; k < tempWord.length; k++){
if( ((i.getKeywords()).get(j)).compareTo(tempWord[k]) == 0){
results.add(i);
match = true;
break;
}
}
if(match == true)
break;
}
}
System.out.println("Results:");
System.out.println(results);
for(int i = 0; i < results.size(); i++){
String avail = "is";
if((results.get(i)).isCheckedOut())
avail = "not";
System.out.println((results.get(i)).getMagicCode() + ": " + (results.get(i)).getTitle() + ",by " + (results.get(i)).getAuthor() + " is " + avail + " available.");
result.add((results.get(i)).getMagicCode() + ": " + (results.get(i)).getTitle() + " - " + avail + " available.");
}
return result;
}
public User matchUser(String login, String pass){
User tempUser = null;
System.out.println("hi: " + login);
for(User i: database.getUserbase()){
if(login.compareTo(i.getId()) == 0 && pass.compareTo(i.getPin()) == 0)
tempUser = i;
}
return tempUser;
}
//check out the book
public boolean U2(String book, User user) throws ParseException{
ArrayList<Book> catalog = database.getBooks();
User tempUser = user;
System.out.println("hi," + tempUser.getName());
System.out.println("the book: " + book);
for(Book i: catalog){
if(book.compareTo(i.getMagicCode()) == 0){
if(i.isCheckedOut() == false){
tempUser.addRental(i.getMagicCode()); //book is in user rental
i.setCheckedOut(true); //book is taken out
System.out.println("check out successfully");
return true;
}
}
}
return false;
}
//return a book
public boolean U3(String code) throws ParseException{
ArrayList<Book> catalog = database.getBooks();
for(Book i: catalog){
if(code.compareTo(i.getMagicCode()) == 0){
if(currentUser.returnBook(code)){
currentUser.removeRental(code);
i.setCheckedOut(false); //makes the book available for the public again
return true;
}
}
}
return false;
}
//reflect user information
public boolean U4() throws ParseException{
for(User i: database.getUserbase()){
i.checkAccess();
}
return true;
}
//list a specific user's information
public void L1(){
}
//change user status
public void L2(){
}
//list users for any overdue item
public void L3(){
}
}