I'll try to explain this the best I can.
I have a class called book which creates books that each hold information such as author, title, ISBN code, etc.
Then I have another class called booklist which stores the books in an array list.
In the booklist class I am trying to write a method which displays the books only written by a specific author.
In my book class I have these methods that will help with the method I am creating:
public void addAuthor(String f, String l)
{
author = f + " " + l;
}
public String getAuthor()
{
return author;
}
public void display()
{
System.out.println("Title:\t" + title);
System.out.println("Author:\t" + author);
System.out.println("Year Published:\t" + year);
System.out.println("ISBN Code:\t" + isbn);
System.out.println("Status:\t" + status);
}
This is the method I am trying to create:
public void showBooks (String first, String last)
{
for(Book book : list)
{
if(book.getAuthor() == first + " " + last)
{
book.display();
}
}
}
I can't figure out why showBooks isn't working. It's not displaying anything even after executing these statements:
b1.addAuthor ("Ian","Fleming");
myBooks.showBooks("Ian","Fleming");
Any suggestions?