I can't work out why my compiler is having a problem. I'm trying to pull a simple get method from another class in order to define whether or not a book is loaned.
public String displayBooks(){
for (Book b : book){
if (b.isLoaned() = false){
String loan = "Not currently loaned";
}
else{
String loan = "Currently loaned";
}
return(book.getTitle() + " " + book.getAuthor() + " " );
}
}
I'm receiving an error saying a variable was required when a value was found. note: book is the name of an arraylist I'm storing book objects in.
The line
b.isLoaned() = false
uses an assignment operator where an equality operator should have been used. Assignment requires an Lvalue on the left-hand side (a variable, not a value).
You should in fact rewrite that part to just
!b.isLoaned()
and, considering the wider context, you may consider the following, which will forestall the compiler error awaiting you as soon as you fix the above:
String loan = (b.isLoaned()? "Currently" : "Not currently") + " loaned";
The above replaces your whole if-else
block.