Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

Library

Ads

 
 

Share on Google+Share on Google+

Devang
Library
0 Answer(s)      5 years and 3 months ago
Posted in : Java Beginners
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;
    }


}
Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
Library
; } } import java.util.Scanner; public class Library { public static void
library management
library management   i need java script code for library management system with html
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
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
SSH library for Java
SSH library for Java  SSH library for Java
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
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
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
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
Library Management in Struts. - Struts
Library Management in Struts.  Hi can you give me the application related to Library Management using Struts Or Jsp
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
library files - Development process
library files   Hi members, i am trying to develop a media player in java using netbeans but what library files should i import for this development
Version of cc.tracyzhang>library dependency
List of Version of cc.tracyzhang>library dependency
Version of com.actionbarsherlock>library dependency
List of Version of com.actionbarsherlock>library dependency
Version of com.adlocus>library dependency
List of Version of com.adlocus>library dependency
Version of com.aidangrabe>library dependency
List of Version of com.aidangrabe>library dependency
Version of com.aniways>library dependency
List of Version of com.aniways>library dependency
Version of com.cocosw>library dependency
List of Version of com.cocosw>library dependency
Version of com.cuneytayyildiz>library dependency
List of Version of com.cuneytayyildiz>library dependency