class Book { public String title; public String author; public Book(String t, String a) { title = t; author = a; } public String toString() { return title + " " + author; } public boolean equals(Book book) { return (book instanceof Book) && ((Book)book).title == title && ((Book)book).author == author; } } class Set { private int capacity; Book[] books; private int i; public Set(int c) { capacity = c; books = new Book[capacity]; } public boolean addBook(Book book) { if(i==0) { books[i] = book; i++; return true; } if(i==capacity) { return false; } for(i=1 ; i<=capacity ; i++) { if((books[i].equals(book))==true) { return false; } } if(books[i].equals(book)==false) { books[i] = book; i++; } return true; } } class setMain { public static void main (String []args) { Set s1 = new Set(3); Book b1 = new Book("Aa","Bb"); Book b2 = new Book("Cc","Dd"); Book b3 = new Book("Aa","Bb"); System.out.println(b1); System.out.println(b2); System.out.println(b3); s1.addBook(b1); s1.addBook(b2); s1.addBook(b3); } }