图书馆系统查询
Library System query
我的图书馆系统项目的搜索功能有问题。到目前为止,我的代码可以让您查看这本书是 'available' 还是 'not available'。我想让我的系统也能够显示这本书的所有信息,包括份数、ISBN 等。
这是我用来搜索这本书是否可用的代码。
public String searchTitle(String titleSearch) {
if (titleSearch == null)
return "\n No Books Avaliable ";
for (int i = 0; i < collection.size(); i++){
if (titleSearch.equalsIgnoreCase(collection.get(i).getTitle())) {
return "\n Book Avaliable";
}
}
return "\n No Books Avaliable "; //reachable only if no book found
}
这也是我在 Book
class:
中使用的代码
public Book(int isbn, String author, String title, String genre, int numcopies) {
this.isbn = isbn;
this.author = author;
this.title = title;
this.genre = genre;
this.numcopies = numcopies;
}
public int getISBN() {
return isbn;
}
public String getAuthor() {
return author;
}
public String getTitle() {
return title;
}
public String getGenre() {
return genre;
}
public String toString() {
return "\nISBN: " + isbn + "\nAuthor: " + author + "\nTitle: " + title +
"\nGenre: " + genre + "\nNumber Of Copies " + numcopies +"\n ";
}
如果我没理解错的话;
if(titleSearch.equalsIgnoreCase(collection.get(i).getTitle())){
return "\n Book Avaliable";
}
在这部分代码中,您可以轻松地 return 本书 class 中的字符串方法的结果。这就像 returning 字符串“\n Book Avaliable”。
请记住,您可以像 collection.get(i).toString()
这样调用字符串函数
或者简单的代码就是这样;
if(titleSearch.equalsIgnoreCase(collection.get(i).getTitle())){
return collection.get(i).toString();
}
我的图书馆系统项目的搜索功能有问题。到目前为止,我的代码可以让您查看这本书是 'available' 还是 'not available'。我想让我的系统也能够显示这本书的所有信息,包括份数、ISBN 等。 这是我用来搜索这本书是否可用的代码。
public String searchTitle(String titleSearch) {
if (titleSearch == null)
return "\n No Books Avaliable ";
for (int i = 0; i < collection.size(); i++){
if (titleSearch.equalsIgnoreCase(collection.get(i).getTitle())) {
return "\n Book Avaliable";
}
}
return "\n No Books Avaliable "; //reachable only if no book found
}
这也是我在 Book
class:
public Book(int isbn, String author, String title, String genre, int numcopies) {
this.isbn = isbn;
this.author = author;
this.title = title;
this.genre = genre;
this.numcopies = numcopies;
}
public int getISBN() {
return isbn;
}
public String getAuthor() {
return author;
}
public String getTitle() {
return title;
}
public String getGenre() {
return genre;
}
public String toString() {
return "\nISBN: " + isbn + "\nAuthor: " + author + "\nTitle: " + title +
"\nGenre: " + genre + "\nNumber Of Copies " + numcopies +"\n ";
}
如果我没理解错的话;
if(titleSearch.equalsIgnoreCase(collection.get(i).getTitle())){
return "\n Book Avaliable";
}
在这部分代码中,您可以轻松地 return 本书 class 中的字符串方法的结果。这就像 returning 字符串“\n Book Avaliable”。
请记住,您可以像 collection.get(i).toString()
或者简单的代码就是这样;
if(titleSearch.equalsIgnoreCase(collection.get(i).getTitle())){
return collection.get(i).toString();
}