public class TestLibraryBook {
public static void main(String[] args) {
LibraryBook book1, book2;
book2 = new LibraryBook("Ali's book", "Ali", "1st June", 250);
book1 = book2;
LibraryBook book5, book6;
LibraryBook book3, book4;
LibraryBook book7, book8, book9, book10;
book4 = new LibraryBook("David's Labs", "David", "29 of February", 1);
book3 = book4;
book6 = new LibraryBook("James adventure", "James", "May", 25);
book5 = book6;
book7 = new LibraryBook("James holiday", "Jane", "Jun", 31);
book8 = book7;
book9 = new LibraryBook("James holiday", "Jane", "April", 53);
book10 = book9;
}
}
And this is my second class
public class LibraryBook {
// variables
public String title;
public String author;
public String dueDate;
public int timesLoaned;
// constructor
public LibraryBook(String title, String author, String dueDate, int timesLoaned) {
this.title = title;
this.author = author;
this.dueDate = dueDate;
this.timesLoaned = timesLoaned;
}
// constructor
public LibraryBook() {
title = "no info";
author = "no info";
dueDate = " no info ";
timesLoaned = 0;
}
public boolean equals() {
if (title.equals(title) & author.equals(author)) {
return true;
}
return false;
}
}
I have two classes with objects and references I'm trying to say if their title and author are same they are same. So I want to add boolean equals method in my LibraryBook class so that books with the same title and author should be considered the same irrespective of their dueDate or timesLoaned. I could not do that pls help me.