public class Book { private static int idCounter = 0; private String title; private String authors; private int id; public Book(String title, String authors) { if (title == null || authors == null) { throw new IllegalArgumentException("title or authors is null"); } this.title = title; this.authors = authors; this.id = Book.idCounter++; } public String getTitle() { return this.title; } public String getAuthors() { return this.authors; } public int getId() { return this.id; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((authors == null) ? 0 : authors.hashCode()); result = prime * result + id; result = prime * result + ((title == null) ? 0 : title.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Book other = (Book) obj; if (id != other.id) { return false; } return true; } @Override public String toString() { return this.getTitle() + " by " + this.getAuthors(); } }