0% found this document useful (0 votes)
92 views

Simple Java Program

The document contains the code for a Java library management system. It defines classes and methods for adding members and books, lending and returning books, and displaying member and book details. Arrays are used to store member, book, issue and return information.

Uploaded by

adeshkushwaha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Simple Java Program

The document contains the code for a Java library management system. It defines classes and methods for adding members and books, lending and returning books, and displaying member and book details. Arrays are used to store member, book, issue and return information.

Uploaded by

adeshkushwaha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

import java.io.

*; class library

// importing io package //class starts //creating

{BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); object br

int i,length,counter,special=0,special_2=0,ID_TEMP,BOOK_TEMP,issue_temp,return_temp,COUNTER,te p,date_temp;//intializing or declaring variable String IDNO_temp;//creating an object of string class int ID[]=new int[100]; String NAME[]=new String[100]; String ADDRESS[]=new String[100]; String CONTACT[]=new String[100]; String BOOKS[]=new String[100]; int BOOKS_NO[]=new int[100]; int STOCK[]=new int[100]; String DESCRIPTION[]=new String[100]; int TAKEN[]=new int[100]; String AUTHOR[]=new String[100]; int PRICE[]=new int[100]; int issueDATE[]=new int[100]; int returnDATE[]=new int[100]; //declaring arrays for various fields

library()throws IOException { for(i=0;i<=7;i++) System.out.print("\t");

//constructor

System.out.println(" WELCOME TO LIBRARY MANAGEMENT SYSTEM V 1.0");

main();}

void main()throws IOException { options(); }

//main function

void options()throws IOException { for(i=0;i<=179;i++)

//function giving option for various choice

System.out.print("-"); System.out.println("");

//printing a line

System.out.println("1.ADD MEMBER"); System.out.println("2.MEMBER"); System.out.println("3.BOOKS"); System.out.println("4.ADD BOOKS"); System.out.println("5.LENDING"); System.out.println("6.RETURNING"); System.out.println("7.EXIT"); for(i=0;i<=179;i++) //printing a line

System.out.print("-"); System.out.println("ENTER YOUR CHOICE");

int choice=Integer.parseInt(br.readLine()); switch(choice) { case 1:ADD_MEMBER(); break; case 2:MEMBER(); break; case 3:BOOKS(); break; case 4:ADD_BOOKS(); break; case 5:LENDING(); break; case 6:RETURNING(); break;

//accepting choice from user

//switch case starts

case 7:System.out.println("program is terminated"); break;

default :System.out.println("PLEASE ENTER DIGITS 1 TO 6 TO CONTINUE AND 7 TO EXIT"); for(i=0;i<=7;i++) System.out.print("\n"); main(); break;}} //end of switch case

void ADD_MEMBER()throws IOException { for(i=0;i<=7;i++)

//FUN TO ADD MEMBER OF LIBRARY

System.out.print("\t"); System.out.println("MEMBERSHIP"); if (special<101) //ACEEPTING DETAILS

{ System.out.println("ENTER YOUR NAME"); System.out.println("NOTE:-ONLY LETTER, DIGITS,UNDERSCORE AND $ IS ALLOWED."); NAME[special]=br.readLine();

System.out.println("ENTER YOUR ADDRESS"); ADDRESS[special]=br.readLine(); System.out.println("ENTER YOUR CONTACT NUMBER"); CONTACT[special]=br.readLine();

System.out.println("PLEASE NOTE THAT YOUR ID NO IS "+special+".SORRY YOU CANNOT CHANGE YOUR ID NO WE ARE STILL WORKING ON IT. "); special++;} else System.out.println("SORRY WE CAN HAVE ONLY 100 MEMBERS AND THE LIMIT HAS EXCEEDED.WE ARE WORKING TO INCREASE THE TOTAL ALLOWED MEMBER.SORRY FOR INCONVINIENCE" ) ; options(); } //RETURNING BACK TO FUN //GIVING INDEX NO AS ID NO TO REMOVE COMPLEXITY

void MEMBER()throws IOException { for(i=0;i<=7;i++) System.out.print("\t");

// DETAILS OF USERS

System.out.println(" INFO ABOUT MEMBERS"); System.out.println(" 1.SINGLE MEMBER"); System.out.println(" 2.LIST OF ALL"); System.out.println(" 3.BACK TO OPTIONS");

System.out.println(" NOTE:- THERE ARE"+special +" MEMBER(S)"); if(special==0) //IF NO MEMBER ARE THERE THEN RETURNING BACK TO FUN

{ System.out.println(" AS THERE ARE NO MEMEBER SO RETURNING CONTROL BACK TO OPTIONS"); options(); } int member_temp=Integer.parseInt(br.readLine()); if(member_temp==1) {

System.out.println(" PLEASE ENTER THE ID NUMBER OF THE MEMBER"); COUNTER=Integer. parseInt(br.readLine()); if(NAME[COUNTER]==null) //TO CECK IF ANY USER WITH THE ID GIVEN EXISTS.

{System.out.println(" MEMBER WITH THIS ID DOSE NOT EXIST"); options(); } else { System.out.println("NAME="+NAME[COUNTER]); System.out.println("ADDRESS="+ADDRESS[COUNTER]); System.out.println("CONTACT NO="+CONTACT[COUNTER]); System.out.println("BOOK TAKEN="+BOOKS[COUNTER]); options(); } }// PRINTING IN A FORMAT FOR EASIER READING

if(member_temp==2) { System.out.println("ID NO" + " "+"NAME"+" "+"CONTACT NO"+" "+"ADDRESS"); for(i=0;i<special;i++) "+"BOOK TAKEN"+"

{System.out.println(i+" "+ADDRESS[i]);

"+NAME[i]+"

"+BOOKS[i]+"

"+CONTACT[i]+"

}options();}if(member_temp==3) options(); }

//RETURUNG BACK TO OPTIONS FUNCTION

void BOOKS()throws IOException { for(i=0;i<=7;i++) System.out.print("\t");

// DETAIL OF BOOKS

System.out.println(" INFO ABOUT BOOKS");

if(special_2==0)

// TO CHECK IF THERE IS ANY BOOK IN DATABASE

{System.out.println("PLEASE ADD BOOKS TO YOUR DATABASE......"); options(); } else { System.out.println("1.SEARCH A SINGLE BOOK"); System.out.println("2.LIST OF ALL"); System.out.println("NOTE:- THE DISRIPTION OF BOOK IS ONLY AVAILABLE IN 1ST OPTION.SORRY FOR INCONVINIENCE"); System.out.println("3.RETURN TO OPTIONS"); System.out.println("ENTER YOUR OPTION AS 1 OR 2 OR 3"); counter=Integer. parseInt(br.readLine()); if(counter==1) // EVERYTHING IS NEARLY SAME AS DONE IN MEMBER();

{System.out.println(" PLEASE ENTER THE BOOK NUMBER OF THE BOOK"); int K=Integer. parseInt(br.readLine()); System.out.println("BOOKS="+BOOKS[K]); System.out.println("STOCK="+STOCK[K]); System.out.println("DESCRIPTION & ADDITIONAL ="+DESCRIPTION[K]); } else if(counter==2) {System.out.println("NOTE :-NULL MEANS NO ONE HAS TAKEN THE BOOK"); System.out.println("BOOK NO"+" "+"DESCRIPTION"+" "+"TAKEN BY"); for(i=0;i<special_2;i++) {System.out.println(i+" "+BOOKS_NO[i]+" "+DESCRIPTION[i]+" "+TAKEN[i]); "+STOCK[i]+" "+"BOOK NAME"+" "+"STOCK"+"

} } else if (counter==3) options(); else {System.out.println("PLEASE ENTER CORRECT CHOICE.RETURNING CONTOL BACK TO OPTIONS"); options(); } } }

void ADD_BOOKS()throws IOException { for(i=0;i<=7;i++) System.out.print("\t"); System.out.println(" STOCK MAINTAINENCE");

// METHOD TO ADD BOOKS TO DATABASE

System.out.println("1.ADD A BOOK TO OLD STOCK IN DATABASE "); System.out.println("2.ADD A NEW BOOK TO DATABASE "); System.out.println("3.RETURN TO OPTIONS"); int K=Integer. parseInt(br.readLine()); switch(K) { case 1 :if(special_2==0) { System.out.println("ADD BOOKS TO YOUR DATABASE FIRST......."); options();} else {System.out.print("PLEASE ENTER THE BOOK CODE"); BOOK_TEMP=Integer. parseInt(br.readLine()); for(i=0;i<=100;i++) {if(BOOKS_NO[i]==BOOK_TEMP) STOCK[i]=STOCK[i]+1; break;}options(); }case 2: //USING SWITCH CASE

if (special_2<=100) { System.out.print("ENTER BOOK NAME-"); BOOKS[special_2]=br.readLine(); System.out.print("ENTER AUTHOR NAME-");

AUTHOR[special_2]=br.readLine(); System.out.print("ENTER STOCK"); STOCK[special_2]=Integer.parseInt(br.readLine()); System.out.print("ENTER PRICE"); PRICE[special_2]=Integer.parseInt(br.readLine()); System.out.print("ENTER DESCRIPTION-"); DESCRIPTION[special_2]=br.readLine(); System.out.println("book code is"+special_2); special_2++;

} else

System.out.print("ERROR ONLY 100 BOOKS CAN BE ADDED ....."); options(); }} void LENDING()throws IOException { for(i=0;i<=7;i++) System.out.print("\t"); System.out.println("ISSUE OF BOOKS "); System.out.println("ENTER YOUR ID NO"); ID_TEMP=Integer.parseInt(br.readLine()); System.out.println("ENTER BOOK CODE"); BOOK_TEMP=Integer.parseInt(br.readLine()); System.out.println("DATE OF ISSUE"); System.out.println("note- only digits");

date_temp

=Integer.parseInt(br.readLine());

for(i=0;i<=special;i++) {if(ID[i]==ID_TEMP&&STOCK[i]>0 )

{ TAKEN[i]=BOOK_TEMP; issueDATE[i]=date_temp; STOCK[i]=STOCK[i]-1; System.out.println("PLEASE PAY RS "+((2.0*PRICE[i])/100.0)); System.out.println("NOTE BOOKS ARE GIVEN AT A RATE OF 2% OF ITS PRICE."); System.out.println(" PLEASE COME AGAIN ..........."); options(); }else System.out.println("BOOK IS NOT IN STOCK or ID NO NOT FOUND ..........."); options(); }

void RETURNING()throws IOException { for(i=0;i<=7;i++) System.out.print("\t"); System.out.println("RETURN OF BOOKS "); System.out.print("ENTER YOUR ID");

ID_TEMP=Integer.parseInt(br.readLine()); System.out.print("ENTER BOOK CODE"); BOOK_TEMP=Integer.parseInt(br.readLine()); System.out.println("DAYS RETAINED"); date_temp =Integer.parseInt(br.readLine());

for(i=0;i<=special;i++) {if(ID[i]==ID_TEMP&&issueDATE[i]>0) { STOCK[i]++; TAKEN[i]=0; issueDATE[i]=0; if(date_temp<7) System.out.println("please come back again");

if(date_temp>7&& date_temp<=14) {System.out.println("due to late submission you are charged RS "+((date_temp-7)*2));

options();

if(date_temp>14) {System.out.println("due to late submission you are charged RS "+(((date_temp14)*20))); options(); }} else {System.out.println("please enter correct id no.or you havent taken any book"); options(); }

} }

You might also like