gpt4 book ai didi

java - 如何为图书馆和图书类制作编辑图书方法

转载 作者:行者123 更新时间:2023-11-30 05:51:09 26 4
gpt4 key购买 nike

我必须制作一个图书馆系统,它有一个 Book 类和一个 Library 类。两者都有编辑书籍的方法。这个概念是图书馆员搜索这本书.. 然后它被克隆.. 克隆的书然后在确认之前进行编辑.. 然后放回图书馆替换以前的书。 Library 类编辑图书方法如下所示:public boolean editBook(String username, Book book),Book 类方法如下所示 public boolean editBook(Book book) .

现在我的问题是 editBook() 方法应该能够编辑书籍的每个属性。一种仅采用一个属性(书籍)并返回一个 boolean 值的方法如何用于编辑标题、作者、权限类型或其中任何一个,这对我来说没有意义,我一直坚持这一点。

最初我认为也许可以在 editBook 方法中获取用户输入,以便允许用户选择他们实际编辑的内容,但我刚刚发现我们不能这样做。

这就是我到目前为止所拥有的,但我被告知我不能使用它,因为它从书籍类调用用户输入,并且它(在本例中)只能从主方法调用用户输入。有人可以指出我正确的方向吗?感谢任何可以提供帮助的人

 Library class method  
public boolean editBook(String username, Book book) throws CloneNotSupportedException{

Book clonedBook = book.clone();
boolean editBook = clonedBook.editBook(clonedBook);
while(editBook){
for(Book b: books){
if(b.getISBNNumber().equalsIgnoreCase(book.getISBNNumber())){
int index = books.indexOf(b);
books.set(index, clonedBook);
}
}
editBook = false;
}
return true;
}


Book class method

public boolean editBook(Book book){
boolean confirm = false;
Scanner scan = new Scanner(System.in);

String y = "";



do{
do{
int x =userInputEnterEditChoice();
editBookSwitch(x);
y = userInputMoreAttibutes();

}while(y.equalsIgnoreCase("y"));

String z = userInputConfirmEdit();


if(confirmEdit(z, book)){
confirm = true;
}
else{
System.out.println("would you like to re edit the book?");
y = scan.nextLine();
}
}while(y.equalsIgnoreCase("y"));



return confirm;
}

最佳答案

Now my problem is that the editBook() method is supposed to be able to edit every single attribute of the book. How does a method that only takes one attribute (Book) and return a boolean supposed to edit the title, or the author, or the permission type or any of those Its not making sense to me and I've been stuck on this.

public class Book {
int id;
String title;
String Author;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return Author;
}
public void setAuthor(String author) {
Author = author;
}
}

public class Library {
public boolean editBook(Book book) {
boolean isEdited = false;
//This is how you edit the attributes of the book
book.id=1;
book.title= "Java Programming";
book.Author= "John Smith";
isEdited = true;
return isEdited;
}

}

关于java - 如何为图书馆和图书类制作编辑图书方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53900338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com