-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.java
More file actions
102 lines (85 loc) · 2.93 KB
/
Library.java
File metadata and controls
102 lines (85 loc) · 2.93 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
public class Library implements itemOperations {
int itemCount=0;
private Library_Item [] items = new Library_Item[10];
public void addItem(Library_Item item) {
if (itemCount < items.length) {
items[itemCount++] = item;
System.out.println("Item has been added"+item);
} else {
System.out.println("Library is full .Can't add more items.");
}
}
public void removeItem(String itemId) {
for (int i = 0; i < itemCount; i++) {
if (items[i].getItemId().equals(itemId)) {
items[i] = items[--itemCount];
items[itemCount] = null;
System.out.println("Item with id" + itemId + "has been removed");
} else {
System.out.println("Item not found.");
}
}
}
public void displayItems() {
for (int i = 0; i < itemCount; i++) {
System.out.println(items[i].toString());
}
}
/* private Book[] books = new Book[10];
int bookCount = 0;
public void addItem()
@Override
public void addBooks(Book book) {
if (bookCount < books.length) {
books[bookCount++] = book;
System.out.println("Book has been added.");
} else {
System.out.println("Library is full");
}
}
@Override
public void removeBook(String itemId) {
for (int i = 0; i < bookCount; i++) {
if (books[i].getItemId().equals(itemId)) {
books[i] = books[--bookCount];
books[bookCount] = null;
System.out.println("Book with id" + itemId + "has been removed");
} else {
System.out.println("Book not found.");
}
}
}
@Override
public void displayBooks() {
for (int i = 0; i < bookCount; i++) {
System.out.println(books[i].toString());
}
}
private Magazine [] magazines = new Magazine[10];
int MagazineCount=0;
public void addMagazine(Magazine magazine) {
if (MagazineCount < magazines.length) {
magazines[MagazineCount++] = magazine;
System.out.println("Magazine has been added.");
} else {
System.out.println("Library is full");
}
}
public void removeMagazine(String itemId) {
for (int i = 0; i < MagazineCount; i++) {
if (magazines[i].getItemId().equals(itemId)) {
magazines[i] = magazines[--MagazineCount];
magazines[MagazineCount] = null;
System.out.println("Magazine with id" + itemId + "has been removed");
} else {
System.out.println("Magazine not found.");
}
}
}
public void displayMagazine() {
for (int i = 0; i < MagazineCount; i++) {
System.out.println(magazines[i].toString());
}
}
*/
}