我創建了這個方法,我不確定它爲什麼說有一個缺少的return語句。我是否需要將印刷品更改爲退貨? (這是最底層的方法)我是一個Java初學者,所以任何幫助將不勝感激!缺少return語句方法ReturnCopy
public class Book {
private String title;
private String author;
private int copies;
private boolean borrowed;
public Book(String inAuthor, String inTitle, int inNumberOfCopies) {
this.author = inAuthor;
this.title = inAuthor;
this.copies = inNumberOfCopies;
}
public void borrowed() {
borrowed = true;
}
public void rented() {
borrowed = true;
}
public void returned() {
borrowed = false;
}
public boolean isBorrowed() {
return borrowed;
}
public String getAuthor() {
return this.author;
}
public static String getTitle() {
return getTitle();
}
public int getTotalCopies() {
return this.copies;
}
public int getAvailableCopies() {
}
public void withdrawCopy() {
int found = 0;
for (Book b : Library.getListOfBooks()) {
if (b.getTitle().equals(title)) {
if (found == 0) {
found = 1;
}
if (!b.isBorrowed()) {
b.borrowed=true;
found = 2;
break;
}
if (found == 0) {
System.out.println("Sorry, this book is not in our catalog.");
} else if (found == 1) {
System.out.println("Sorry, this book is already borrowed.");
} else if (found == 2) {
System.out.println("You successfully borrowed " + title);
}
}
}
}
public String returnCopy() {
boolean found = false;
for (Book book : Library.getListOfBooks()) {
if (getTitle().equals(title) && book.isBorrowed()) {
book.returned();
found = true;
}
if (found) {
System.out.println("you successfully returned " + title);
}
}
}
}
因爲它不是'void'方法,它必須返回一個'String'。換句話說,或將其改爲void或將其更改爲'boolean'(這似乎就是它的意思) – Maljam