-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
54 lines (46 loc) · 2.01 KB
/
Student.java
File metadata and controls
54 lines (46 loc) · 2.01 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
import java.sql.SQLException;
import java.util.*;
public class Student extends User {
private String name;
Student(String name, String id, String password) { //Constructor for Student which takes 3 arguments and initializes the parameters
this.name = name;
this.id = id;
super.setPassword(password);
}
public String getName() { //Gets the name of the student
return name;
}
public void setName(String name) { //Sets the name of the student
this.name = name;
}
@Override
public String toString() { //Returns the name instance field of the Student class
return "Name: " + this.getName()+"\nId: "+this.getID()+"\n";
}
public void borrowBook(String name) throws SQLException, ClassNotFoundException, InterruptedException { //Issues a book to the student
Database_DAO dao = new Database_DAO();
int idno = dao.getUserId(this.getID());
int a = dao.issueBookDB(idno, name);
if(a==-1) System.out.println("Max Limit Reached");
else if(a==1) System.out.println("Book Issued");
else System.out.println("Issue failed");
}
public void returnBook(String name) throws SQLException, ClassNotFoundException { //A book is returned by the student
int idno = new Database_DAO().getUserId(this.getID());
if (idno != 0) {
HashMap<Double, Double> hs = new Database_DAO().returnBookDB(idno, name);
for (Double d : hs.keySet()) {
if (d != 0) {
System.out.println("Dues: " + hs.get(d));
} else
System.out.println("Cannot return book");
}
}
}
public void reissueBook(String name) throws SQLException, ClassNotFoundException, InterruptedException {
Database_DAO dao = new Database_DAO();
int a = dao.reissueBookDB(name);
if(a!=0) System.out.println("Book re-issued successfully");
else System.out.println("Can't reissue this book");
}
}