-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBook.java
108 lines (80 loc) · 2.05 KB
/
Book.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
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
/*
Object Oriented Analysis & Design
Assignment #1
Section: CS-A
1. Name: Mohsin Hayat | Roll Number: L16-4333
2. Name: Aanish Amir | Roll Number: L16-4144
*/
package lms;
import java.util.LinkedList;
import java.util.Queue;
public class Book {
String Name;
String Author;
String ISBN;
String Status;
Queue<User> reserve = new LinkedList<>();
int quantity;
public Book(String Name, String Author, String ISBN, int quantity) {
this.Name = Name;
this.Author = Author;
this.ISBN = ISBN;
this.Status = "available";
this.quantity = quantity;
if(this.quantity == LMS.totalOccupied(ISBN)){
this.Status = "not available";
}
}
public String getName() {
return Name;
}
public String getAuthor() {
return Author;
}
public String getISBN() {
return ISBN;
}
public int getQty() {
return quantity;
}
public void setName(String Name) {
this.Name = Name;
}
public String getStatus() {
return Status;
}
public void setAuthor(String Author) {
this.Author = Author;
}
public void setISBN(String ISBN) {
this.ISBN = ISBN;
}
public void updateStatus(String newStatus){
this.Status = newStatus;
}
public void setQuantity(int qty) {
this.quantity = qty;
if(this.quantity == LMS.totalOccupied(this)){
this.Status = "not available";
}
}
protected boolean reserveBook(User u){
if(this.Status.equals("unavailable")){
return false;
}
if(this.reserve.contains(u)){
return false;
}
this.reserve.add(u);
return true;
}
protected boolean isReserved(User u){
return this.reserve.contains(u);
}
public int getReservationSize() {
return this.reserve.size();
}
public User topInQ(){
return reserve.peek();
}
}