Library

Library

public class Book 
{
    String bookName,author;
    int bookId,noOfCopies;
    public String getBookName() {
        return bookName;
    }
    public void setBookName(String bookName) {
        this.bookName = bookName;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public int getBookId() {
        return bookId;
    }
    public void setBookId(int bookId) {
        this.bookId = bookId;
    }
    public int getNoOfCopies() {
        return noOfCopies;
    }
    public void setNoOfCopies(int noOfCopies) {
        this.noOfCopies = noOfCopies;
    }

}


import java.util.Scanner;


public class Library 
{
    public static void main(String args[])
    {
        LibraryImpl l1= new LibraryImpl();
        int ch=0;
        do
        {

            System.out.println("Menu");
            System.out.println("1.Add Books");
            System.out.println("2.Add Student");
            System.out.println("3.issue books");
            System.out.println("4.return books");
            System.out.println("5.search book");
            System.out.println("Enter ur choice");
            Scanner s=new Scanner(System.in);
            ch=s.nextInt();
            switch(ch)
            {
            case 1:
                l1.addbooks();
                break;
            case 2:
                l1.addstudent();
                break;
            case 3:
                l1.issuebooks();
                break;
            case 4:
                l1.returnbooks();
                break;
            case 5:
                l1.searchbooks();
                break;
                default:
                    System.out.println("wrong choice");

            }

        }while((ch>0) && (ch<6));
    }

}

import java.util.ArrayList;
import java.util.Scanner;


public class LibraryImpl
{
    ArrayList<Book> bookList=new ArrayList<Book>();
    ArrayList<Student> stuList=new ArrayList<Student>();

    int[] arr=new int[5];
    public void addbooks()
    {
        Book b1=new Book();
        System.out.println("Enter the name of the book");
        Scanner s1=new Scanner(System.in);
        String name=s1.nextLine();
        b1.setBookName(name);
        System.out.println("Enter book id");
        int id=s1.nextInt();
        b1.setBookId(id);
        System.out.println("enter author");
        String author=s1.next();
        b1.setAuthor(author);
        System.out.println("enter no of copies");
        int copies=s1.nextInt();
        b1.setNoOfCopies(copies);
        bookList.add(b1);

    }

    public void addstudent()
    {
        Student s1=new Student();
        System.out.println("Enter the name ");
        Scanner sc1=new Scanner(System.in);
        String name=sc1.nextLine();
        s1.setSname(name);
        System.out.println("Enter student id");
        int id=sc1.nextInt();
        s1.setSid(id);
        System.out.println("enter no of copies");
        int copies=sc1.nextInt();
        s1.setNoc(copies);
        stuList.add(s1);

    }


    public void issuebooks()
    {   

        System.out.println("Enter book id");    
        Scanner sc=new Scanner(System.in);
        int id=sc.nextInt();
        for(Book b:bookList)
        {
            if(b.getBookId()==id)
            {
                if(b.getNoOfCopies()== 0)
                    System.out.println("Book not available");
                else
                    checkStud(b);
            }
        }
    }

    public void checkStud(Book obj)
    {
        System.out.println("Enter student id");     
        Scanner sc=new Scanner(System.in);
        int sid=sc.nextInt();
        for(Student stud:stuList)
        {
            if(stud.getSid()==sid)
            {
                if(stud.getNoc()<5)
                {
                    System.out.println("Book Issued");
                    stud.setNoc(stud.getNoc()+1);
                    obj.setNoOfCopies(obj.getNoOfCopies()-1);
                }
                else
                    System.out.println("Only 5 books can be issued");
            }
        }
    }

    public void returnbooks()
    {   

        System.out.println("Enter book id");    
        Scanner sc=new Scanner(System.in);
        int id=sc.nextInt();
        for(Book b:bookList)
        {
            if(b.getBookId()==id)
            {
                b.setNoOfCopies(b.getNoOfCopies()+1);
                    callStud();
            }
        }
    }
    public void callStud()
    {
        System.out.println("Enter student id");     
        Scanner sc=new Scanner(System.in);
        int sid=sc.nextInt();
        for(Student stud:stuList)
        {
            if(stud.getSid()==sid)
            {

                    System.out.println("Book Returned");
                    stud.setNoc(stud.getNoc()-1);

                }
                else
                    System.out.println("Invalid user");
            }
        }

    public void searchbooks()
    {
        System.out.println("Enter the name of the book");
        Scanner sc=new Scanner(System.in);
        String name=sc.next();
        for(Book b:bookList)
        {
            if(b.getBookName().equalsIgnoreCase(name))
            {
                System.out.println("The details are:"+b.getBookName()+" "+b.getAuthor()+" "+b.getNoOfCopies());
            }

        }

    }
}

public class Student
{
    String sname;
    int sid,noc;
    public String getSname() {
        return sname;
    }
    public void setSname(String sname) {
        this.sname = sname;
    }
    public int getSid() {
        return sid;
    }
    public void setSid(int sid) {
        this.sid = sid;
    }
    public int getNoc() {
        return noc;
    }
    public void setNoc(int noc) {
        this.noc = noc;
    }


}
View Answers

Ads









Related Tutorials/Questions & Answers:
Library
; } } import java.util.Scanner; public class Library { public static void
library
Advertisements
library management
library management   i need java script code for library management system with html
library management
library management   i need java script code for library management system with html
library management
library management   i need java script code for library management system with html
library management
library management   i need java script code for library management system with html
native library
native library  how to create native library in java
library system
library system  hi to all..please help me how to make a library system using a java program..please response me
library system
library system  hi to all..please help me how to make a library system using a java program..please response me
netbeans library
for a book library please.The program should provide a menu of options to work with the library, including: 1) Adding a new item to the library 2) Viewing all stock in the library 3) Lending an item 4) Returning an item 5) Exiting
netbeans library
for a book library please.The program should provide a menu of options to work with the library, including: 1) Adding a new item to the library 2) Viewing all stock in the library 3) Lending an item 4) Returning an item 5) Exiting
Ajax library
Ajax library  Hi, What is Ajax Library? List down the latest ajax libraries. Thanks   Hi, Ajax allows the developers to build Ajax based rich internet applications. Ajax libraries is the packaged components
XAJAX Library
XAJAX Library       xajax is an open source PHP class library that allows you to easily create powerful, web-based, Ajax applications using HTML, CSS, JavaScript, and PHP. Applications
SSH library for Java
SSH library for Java  SSH library for Java
library management system
library management system  coding for library management system
A better Java JSON library?
A better Java JSON library?   A better Java JSON library
ModuleNotFoundError: No module named 'A-library'
ModuleNotFoundError: No module named 'A-library'  Hi, My Python... 'A-library' How to remove the ModuleNotFoundError: No module named 'A-library' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'it_library'
ModuleNotFoundError: No module named 'it_library'  Hi, My Python... 'it_library' How to remove the ModuleNotFoundError: No module named 'it_library' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'Library'
ModuleNotFoundError: No module named 'Library'  Hi, My Python... 'Library' How to remove the ModuleNotFoundError: No module named 'Library... to install padas library. You can install Library python with following command
tag library descriptor
tag library descriptor  i need types of tld ,uses of tld and example program for tag library descriptor
Form Tag library configuration
In this section, you will learn about Spring form tag library and its configuration
library management project
library management project  Is there any similiar methods to that of sendredirect in java
library management project
library management project  Is there any similiar methods to that of sendredirect in java
Java FTP Library
Java FTP Library  Which all Java FTP Library available in market? Is there any free open source Java FTP Library? Thanks   Hi, Both open source and commercial Java FTP library are available on Internet. Most used open
online library management
online library management  how to divert user from log in page to home page depending on their category(like student or staff in case of ol library) using java servlet
Microsoft ajax library
Microsoft ajax library  Hi, I am .NET developer. Give me the url of microsoft ajax library
all c library functions
all c library functions  hi dear c coders, i need all c library functions with a detailed explanation. Who can give me usefull link? thanks beforehand!   Hi Friend, Please go through the following link: C Tutorials
save uiimage to photo library
on camera roll in iPhone. I always want to write the file into photo library.   Save UIImage to photo library Creating a camera application in iPhone need... into photo library 3) and check if the image have been saved into your library
What is a machine learning library?
What is a machine learning library?  Hi, I am beginner in Data...: What is a machine learning library? Try to provide me good examples or tutorials links so that I can learn the topic "What is a machine learning library
Runtime shared library
Runtime shared library  Hi....... Please just tell me about What are runtime shared libraries in flex? Thanks  Ans: Run time shared library is One way to reduce the size of your applications' SWF files
FieldTalk Library For Java
FieldTalk Library For Java   i m developing s/w scada.in this software i am using MODBUS RTU Protocol for communication. Can u tell me how will it happen. I searched on internet, then i found that Java FieldTalk Libray is being

Ads