Question: public class book { public String name,author; int year; public book ( String namei,String authori,int yeari ) { name = namei;author = authori;year = yeari;

public class book
{ public String name,author;
int year;
public book(String namei,String authori,int yeari)
{name=namei;author=authori;year=yeari;}
public book(book bi)
{name=bi.name;author=bi.author;year=bi.year;}
public String toString()
{String s="book name ="+name+" book author ="+author+" publication year ="+year+"
";
return s;
}
}
import java.util.*;
public class library
{
String name;
int number_of_books;
TreeMap book_name = new TreeMap();
TreeMap author_name = new TreeMap();
public library(String kname)
{name=kname;
number_of_books=0;
}
public void add(book b)
{
book_name.put(b.name,b);
author_name.put(b.author,b);
number_of_books=book_name.size();
}
public void remove(book b)
{
number_of_books--;
book_name.remove(b.name);
author_name.remove(b.author);
number_of_books=book_name.size();
}
public String list_with_name()
{String s=book_name.values().toString();
return s;
}
public String list_with_author()
{String s=author_name.values().toString();
return s;
}
public String get_with_name(String name)
{String s=book_name.get(name).toString();
return s;
}
public String toString_with_name()
{ String s="Library name : "+name+"
";
s+="Total number of books : "+number_of_books+"
";
s+=list_with_name()+"
";
return s;
}
public String toString_with_author()
{ String s="Library name : "+name+"
";
s+="Total number of books : "+number_of_books+"
";
s+=list_with_author();
return s;
}}
Add books to the library and print them out according to authors and according to names

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!