code for library.java
import java.util.ArrayList;
public class Library {
private String libraryName,libAddress;
Library(String libraryName,String libAddress)
{
this.libraryName = libraryName;
this.libAddress =libAddress;
}
public String getLibraryName() {
return libraryName;
}
public void setLibraryName(String libraryName) {
this.libraryName = libraryName;
}
public String getLibAddress() {
return libAddress;
}
public void setLibAddress(String libAddress) {
this.libAddress = libAddress;
}
ArrayList<Book> bookList = new ArrayList<Book>();
ArrayList<Member> memberList = new ArrayList<Member>();
public void addBook(Book book)
{
bookList.add(book);
}
public void bookInfo()
{
for (int i=0; i< bookList.size(); i++)
{
System.out.println("Author of " +bookList.get(i).getName()+" is "+bookList.get(i).getAuthorName());
}
}
public void getBookLend(String bookName) //function call to check the name of person to whom book is issued
{
System.out.println(bookName);
for(Book boo : bookList)
if(bookName.equals(boo.getName()))
{
System.out.println("In Loop "+boo.getName());
System.out.println(boo.getNameOfPerson());
System.out.println("Book Issued To " +boo.getNameOfPerson()); //ERROR HERE. GETTING NULL WHY???
}
}
}
code for member.java
import java.util.ArrayList;
public class Member {
String memberName;
int id;
ArrayList<Member> memberList = new ArrayList<Member>();
public Member(String memberName, int id) {
this.memberName = memberName;
this.id = id;
}
public String getMemberName() {
return memberName;
}
public void setMemberName(String memberName) {
this.memberName = memberName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public ArrayList<Member> getMemberList() {
return memberList;
}
public void setMemberList(ArrayList<Member> memberList) {
this.memberList = memberList;
}
public void addMember(Member member)
{
memberList.add(member);
System.out.println(member.memberName +" added Successully as a member");
}
public void showMember()
{
for(Member member : memberList)
System.out.println(member.getMemberName());
}
}
Code for book.java
public class Book {
private String name,authorName,catagory;
private int noOfCopies,bookId;
private String nameOfPerson;
Book(String name ,int bookId,String authorName,String catagory,int noOfCopies)
{
this.name =name;
this.authorName=authorName;
this.catagory =catagory;
this.noOfCopies = noOfCopies;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthorName() {
System.out.println("nutan");
return authorName;
}
public void setAuthorName(String authorName) {
this.authorName = authorName;
}
public String getCatagory() {
return catagory;
}
public void setCatagory(String catagory) {
this.catagory = catagory;
}
public int getNoOfCopies() {
return noOfCopies;
}
public void setNoOfCopies(int noOfCopies) {
this.noOfCopies = noOfCopies;
}
public String getNameOfPerson() {
return nameOfPerson;
}
public void setNameOfPerson(String nameOfPerson) {
this.nameOfPerson = nameOfPerson;
}
public void bookLend(int bookId,String nameOfPerson) //function called when a book is issued
{
if(noOfCopies == 0)
System.out.println("Non Applicable");
else
{
noOfCopies--;
this.nameOfPerson = nameOfPerson;
this.setNameOfPerson(this.nameOfPerson);
System.out.println("book issued to \t"+getNameOfPerson() +"\t");
System.out.println("Number Of Available copies \t" +noOfCopies);
}
}
}
Code for Execution.java
public class Execution {
public static void main(String[] args) {
Library lib = new Library("Universal Library","MUMBAI"); //Library Constructor
Book book1 = new Book("Book Java",1,"Scmidt","computers",1);
Book book2 = new Book("C++",2,"Bjarne","computers",6); //Book Objects
Book book3 = new Book("C",3,"Yaswant","computers",4);
Book book4 = new Book("Adobe Basics",4,"Mr.","basics",3);
Book book5 = new Book("Learning",5,"Paul","english",2);
Book book6 = new Book("How To?",6,"Ravi","vhut",1);
Member member1 = new Member("nn", 01);
Member member2 = new Member("ri", 02); //Members objects
lib.addBook(book1);
lib.addBook(book2);
lib.addBook(book3); //calling addBook function to add books in the list
lib.addBook(book4);
lib.addBook(book5);
lib.addBook(book6);
member1.addMember(member1);
member2.addMember(member2);
book6.bookLend(6,"nu"); //function to issue books
lib.getBookLend("C++"); // function call to find out whom book is issued
}
}