Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Devang
Library
0 Answer(s)      2 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;
    }


}

Advertisement
View Answers

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
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
SSH library for Java
SSH library for Java  SSH library for Java
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
A better Java JSON library?
A better Java JSON library?   A better Java JSON library
library management system
library management system  coding for library management system
tag library descriptor
tag library descriptor  i need types of tld ,uses of tld and example program for tag library descriptor
library management project
library management project  Is there any similiar methods to that of sendredirect in java
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 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
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
Tag library - JSP-Servlet
Tag library  Hi, although i read a lot about tag library in jsp but it's not clear to me please tell me what is tag library and why it's use in struts. Please give me some simple example so that i can make my concept clear
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
chart library - Java3D
JFreeChart library jar files" and click for download files. Thanks
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
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
Bindows animation library
Bindows animation library       Bindows animation library enables adding animations to Bindows components - thus creating visual effects like pulsating buttons, fade-ins, fade-outs
Library Management System
Library Management System  Hello I am developing program of library management system where I need to use C++ but without class. So I am facing...; struct library { char isbn[10],b_name[15],a_name[15],search[10]; }stud[100
library management system jsp project
library management system jsp project  i need a project of library management system using jsp/java bean
library management system jsp project
library management system jsp project  i need a project of library management system using jsp/java bean
library management system jsp project
library management system jsp project  i need a project of library management system using jsp/java bean
Cannot find tag library descriptor
Cannot find tag library descriptor  Cannot find tag library descriptor...? How to resolve in struts in eclipse
use netbean develop a library system
use netbean develop a library system  Hi could someone build a program in netbeans 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
Ajaxed Library
Ajaxed Library       The ajaxed Library comes up with an unique Ajax technique which can be used within your classic ASP applications. You will be able to create Rich Web Applications
JSP Controls Tag Library
JSP Controls Tag Library       JSP Controls Tag Library provides the lifecycle for portlet-like JSP components. The Library does not require a portal engine or other central controller
AJAX Dev Library
AJAX Dev Library       AJAX Dev Library ADL Pack series is the extension package for Joyistar WebShop... library. Read full Description
Developer Open Source Library
Developer Open Source Library Introduction of moo.fox moo.fx is a super lightweight, ultratiny, megasmall JavaScript effects library, written..., check out the Combo Library.    Open Source script.aculo.us
The AJAX JSP Tag Library
The AJAX JSP Tag Library       The AJAX JSP Tag Library is a set of JSP tags that simplify the use... library eases development by not forcing J2EE developers to write the necessary
How to invoke method of a library from command line
How to invoke method of a library from command line  Suppose there are two methods in a libray and you have to invoke one of the method from that library directly from the command prompt. How will you do
how i can get jqfade.js library
how i can get jqfade.js library  how i can get jqfade.j script library
MYSQL Java Connector Library
Where to download the MYSQL Java Connector Library and get the jar file... connector library into your Java application folder. MYSQL Java connector library is required to establish a connection in between your Java application
Help on this java code for online library search
Help on this java code for online library search   I have written the following java code for simple library book search. but its having some errors...*; public class Library { JRadioButton rbauthor = new JRadioButton("Search by Author
Eclipse juno failed to load the jni shared library
the error "Eclipse juno failed to load the jni shared library". Let's know what
What is a Tag Library in JSP
What is a Tag Library in JSP   ... explanation of the Tag Library in JSP. In the Java Server Pages Technology..., you can say that the tag library is a collection of custom tags. The Tag
Create Tag Library Descriptor (TLD) File
Create Tag Library Descriptor (TLD) File  ..., we learn how to create library descriptor file in your project. Developers can... library descriptor file (TLD file) is used to describe the tag extensions and relate
 

 

 

DMCA.com