Initial commit

This commit is contained in:
xixu-me committed 2024-03-17 22:31:48 +08:00
commit 054b77ccdd
27 files changed
+1362

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Test",
"request": "launch",
"mainClass": "Test",
"projectName": "LibraryManagementSystem"
}
]
}
@@ -0,0 +1,55 @@
public class Administrator {
private int iId;
private String strName;
private Library lib;
public Administrator(int inId, String inName) {
this.iId = inId;
this.strName = inName;
this.lib = new Library();
}
public boolean register(Student st) {
for (Book bk : st.getBg().getLiBag())
if (!this.lib.del(bk)) {
System.out.println("Book not found in library: " + bk.getStrIsbn());
return false;
}
this.print(st);
return true;
}
private void print(Student st) {
System.out.println("Administrator ID: " + this.iId);
System.out.println("Administrator Name: " + this.strName);
System.out.println("Student ID: " + st.getiId());
System.out.println("Student Name: " + st.getStrName());
for (Book bk : st.getBg().getLiBag())
System.out.println(
"Book ISBN: " + bk.getStrIsbn() + " Title: " + bk.getStrTitle() + " Count: " + bk.getiCount());
}
public int getiId() {
return iId;
}
public void setiId(int iId) {
this.iId = iId;
}
public String getStrName() {
return strName;
}
public void setStrName(String strName) {
this.strName = strName;
}
public Library getLib() {
return lib;
}
public void setLib(Library lib) {
this.lib = lib;
}
}
+36
View File
@@ -0,0 +1,36 @@
import java.util.ArrayList;
import java.util.List;
public class Bag {
private List<Book> liBag;
public Bag() {
this.liBag = new ArrayList<Book>();
}
public void add(Book bk) {
this.liBag.add(bk);
}
public boolean del(String inIsbn) {
boolean flag = false;
Book tempBk;
for (int i = 0; i < this.liBag.size(); i++) {
tempBk = this.liBag.get(i);
if (tempBk.getStrIsbn().equals(inIsbn)) {
this.liBag.remove(i);
flag = true;
break;
}
}
return flag;
}
public List<Book> getLiBag() {
return liBag;
}
public void setLiBag(List<Book> liBag) {
this.liBag = liBag;
}
}
+35
View File
@@ -0,0 +1,35 @@
public class Book {
private String strIsbn;
private String strTitle;
private int iCount;
public Book(String inIsbn, String inTitle, int inCount) {
this.strIsbn = inIsbn;
this.strTitle = inTitle;
this.iCount = inCount;
}
public String getStrIsbn() {
return strIsbn;
}
public void setStrIsbn(String strIsbn) {
this.strIsbn = strIsbn;
}
public String getStrTitle() {
return strTitle;
}
public void setStrTitle(String strTitle) {
this.strTitle = strTitle;
}
public int getiCount() {
return iCount;
}
public void setiCount(int iCount) {
this.iCount = iCount;
}
}
+39
View File
@@ -0,0 +1,39 @@
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;
}
}
+39
View File
@@ -0,0 +1,39 @@
public class Student {
private int iId;
private String strName;
private Bag bg;
public Student(int inId, String inName) {
this.iId = inId;
this.strName = inName;
this.bg = new Bag();
}
public void addBook(Book bk) {
this.bg.add(bk);
}
public int getiId() {
return iId;
}
public void setiId(int iId) {
this.iId = iId;
}
public String getStrName() {
return strName;
}
public void setStrName(String strName) {
this.strName = strName;
}
public Bag getBg() {
return bg;
}
public void setBg(Bag bg) {
this.bg = bg;
}
}
+13
View File
@@ -0,0 +1,13 @@
public class Test {
public static void main(String[] args) {
Administrator adm = new Administrator(1, "John");
adm.getLib().add(new Book("123", "Book1", 1));
adm.getLib().add(new Book("124", "Book2", 1));
adm.getLib().add(new Book("125", "Book3", 1));
Student st = new Student(1, "Alice");
st.getBg().add(new Book("123", "Book1", 1));
st.getBg().add(new Book("124", "Book2", 1));
st.getBg().add(new Book("125", "Book3", 1));
adm.register(st);
}
}