This commit is contained in:
xixu-me committed 2024-03-30 16:39:21 +08:00
1 parent 062beda77e
commit b0055a87bd
25 files changed
+40 -93

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
package library;
import java.util.ArrayList;
import java.util.List;
public class Library {
private List<Book> liLib;
public Library() {
this.liLib = new ArrayList<Book>();
}
public void add(Book bk) {
Book tempBk;
for (int i = 0; i < this.liLib.size(); i++) {
tempBk = this.liLib.get(i);
if (tempBk.getStrIsbn().equals(bk.getStrIsbn())) {
tempBk.setiCount(tempBk.getiCount() + bk.getiCount());
return;
}
}
this.liLib.add(bk);
}
public boolean del(Book bk) {
Book tempBk;
for (int i = 0; i < this.liLib.size(); i++) {
tempBk = this.liLib.get(i);
if (tempBk.getStrIsbn().equals(bk.getStrIsbn())) {
if (tempBk.getiCount() > bk.getiCount()) {
tempBk.setiCount(tempBk.getiCount() - bk.getiCount());
return true;
} else if (tempBk.getiCount() == bk.getiCount()) {
this.liLib.remove(i);
return true;
}
}
}
return false;
}
}