Beruflich Dokumente
Kultur Dokumente
Vector;
class Book { String name,author,id; float price; byte total_copies,issued; public Book() { name=null; author=null; id=null; total_copies=issued=0; }
public Book(String a,String b,String c,float d,byte e) { name=a; author=b; id=c; price=d; total_copies=e; } }
class Transaction { byte day_of_issue,month_of_issue; byte day_of_return,month_of_return; short year_of_issue,year_of_return; float fine=0.0f;
public Transaction() {
public void issue_date()throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the day of issue:"); day_of_issue=Byte.parseByte(b.readLine()); System.out.print("Enter the month of issue:"); month_of_issue=Byte.parseByte(b.readLine()); System.out.print("Enter the year of issue:"); year_of_issue=Short.parseShort(b.readLine()); }
public void return_date()throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the day of return:"); day_of_return=Byte.parseByte(b.readLine()); System.out.print("Enter the month of return:"); month_of_return=Byte.parseByte(b.readLine()); System.out.print("Enter the year of return:"); year_of_return=Short.parseShort(b.readLine());
public short calc_days() { byte i; short days=0; if(year_of_issue==year_of_return) { if(month_of_issue==month_of_return) { days=(short)(day_of_return-day_of_issue); } else { days+=calc_no_of_days(month_of_issue,year_of_issue)-day_of_issue; for(i=(byte)(month_of_issue+1);i<month_of_return;i++) { days+=calc_no_of_days(i,year_of_issue); } days+=day_of_return; } } else { days+=calc_no_of_days(month_of_issue,year_of_issue)-day_of_issue; for(i=(byte)(month_of_issue+1);i<=12;i++)
public short calc_no_of_days(byte month,short year) { short d=0; switch(month) { case 2:if(year%4==0) d= 29; else d=28;
case 12:d=31;
public void calc_fine(String name,String author,String r,Member m) { Book b=((Book)x[find_book(name,author)]); if(r.equalsIgnoreCase("y")) { m.t.fine+=b.price; b.total_copies--; b.issued--; books.setElementAt(b,find_book(name,author)); } else if(m.t.calc_days()>7) { m.t.fine+= (m.t.calc_days())*(2.0f); } }
public int find_book(String name,String author) { boolean flag=true; if(x.length>0) { int i=0; while(flag && i<x.length) { if(name.equals(((Book)x[i]).name) && author.equals(((Book)x[i]).author)) { flag=false; } else i++; }
public void decrement(int pos_book,int pos_mem) { Book b=((Book)x[pos_book]); b.total_copies--; b.issued++; books.setElementAt(b,pos_book); Member m=(Member)y[pos_mem]; m.issued=null; members.setElementAt(m,pos_mem); update(); }
public void increment(int pos_book,int pos_mem) { Book b=((Book)x[pos_book]); b.total_copies++; b.issued--; books.setElementAt(b,pos_book); Member m=(Member)y[pos_mem]; m.issued=b; members.setElementAt(m,pos_mem); update(); }
{ boolean flag=true; if(x.length>0) { int i=0; while(flag && i<x.length) { if((name.equals(((Book)x[i]).name) && author.equals(((Book)x[i]).author))|| id.equals(((Book)x[i]).id)) { flag=false; } else i++; }
public int find_member(String id) { boolean flag=true; if(y.length>0) { int i=0; while(flag && i<y.length) { if(id.equals(((Member)y[i]).id)) { flag=false; } else i++; }
public void add_book()throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter name of the book:"); String name=b.readLine(); System.out.print("Enter the author's name:"); String author=b.readLine(); System.out.print("Enter the book id:"); String id=b.readLine(); if(find_book(name,author,id)!=-1) { System.out.println("Either the book is already in the list or the ID has to be different"); } else { System.out.print("Enter the price:"); float pr=Float.parseFloat(b.readLine()); System.out.print("Enter the number of copies:"); byte cop=Byte.parseByte(b.readLine()); books.addElement(new Book(name,author,id,pr,cop)); System.out.println("Added"); update(); } }
public void delete_book()throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the name of the book to be deleted:"); String name=b.readLine(); System.out.print("Enter the author's name of the book:"); String author=b.readLine(); if(find_book(name,author)!=-1) { books.removeElementAt(find_book(name,author)); System.out.println("Deleted."); } else { System.out.println("The entered book is not there in the list at all."); } update(); }
public void add_member()throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter your name:"); String name=b.readLine(); System.out.print("Enter the id:"); String id=b.readLine();
if(find_member(id)!=-1) { System.out.println("This ID is already given to another member"); } else { members.addElement(new Member(name,id)); System.out.println("Added"); update(); } }
public void delete_member()throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the member id:"); String id=b.readLine(); if(find_member(id)!=-1) { members.removeElementAt(find_member(id)); System.out.println("Terminated"); } else { System.out.println("The member is not there in the list at all"); }
update(); }
public void issue()throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the member id:"); String id=b.readLine(); if(find_member(id)==-1) { System.out.println("You are not a member of the library at all"); } else { System.out.print("Enter the book name:"); String name=b.readLine(); System.out.print("Enter the author's name:"); String author=b.readLine(); if(find_book(name,author)==-1 || ((Book)x[find_book(name,author)]).total_copies==2) { System.out.println("Sorry.The book is not available"); } else if(((Member)y[find_member(id)]).issued!=null) { System.out.println("You have already issued a book"); }
public void return_book()throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the book name:"); String name=b.readLine(); System.out.print("Enter the author name:"); String author=b.readLine(); System.out.print("Enter the member ID:"); String id=b.readLine(); Member m=(Member)y[find_member(id)]; System.out.print("Have you lost the issued book?"); String r=b.readLine(); if(r.equalsIgnoreCase("y")) { calc_fine(name,author,r,m);
members.setElementAt(m,find_member(id)); } else { m.t.return_date(); calc_fine(name,author,r,m); members.setElementAt(m,find_member(id)); increment(find_book(name,author),find_member(id)); } System.out.println("Your fine is:"+m.t.fine); update(); }
public void receive_fine()throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter your id:"); String id=b.readLine(); if(find_member(id)!=-1) { Member m=(Member)y[find_member(id)]; System.out.println("Please enter the fine amount paid by the member:"); m.t.fine-=Float.parseFloat(b.readLine()); m.issued=null; members.setElementAt(m,find_member(id)); update();
class Lib { public static void main(String[] a)throws IOException { Library l=new Library(); String resp; BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); do { System.out.println(); System.out.println("What do you want to do?"); System.out.println("1.ADD A BOOK\n2.DELETE A BOOK\n3.ADD A MEMBER"); System.out.println("4.TERMINATE A MEMBER\n5.ISSUE A BOOK\n6.RETURN A BOOK"); System.out.println("7.ACCEPT FINE"); switch(Byte.parseByte(b.readLine())) { case 1:l.add_book(); break;
default:System.out.println("Invalid choice"); break; } System.out.println(); System.out.print("Want to do any more operations?"); resp=b.readLine(); }while(resp.equalsIgnoreCase("y"));
} } /* OUTPUT: What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 1 Enter name of the book:App Chem Enter the author's name:Jain Enter the book id:B1 Enter the price:120 Enter the number of copies:12 Added
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER
4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 1 Enter name of the book:App Math Enter the author's name:Kumbojkar Enter the book id:B2 Enter the price:130 Enter the number of copies:11 Added
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 1 Enter name of the book:App Phy Enter the author's name:Nandu Enter the book id:B2
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 1 Enter name of the book:App Phy Enter the author's name:Nandu Enter the book id:B3 Enter the price:140 Enter the number of copies:20 Added
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER
4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 1 Enter name of the book:Comp Prog Enter the author's name:Herbett Enter the book id:B4 Enter the price:129 Enter the number of copies:14 Added
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 2 Enter the name of the book to be deleted:App Phy Enter the author's name of the book:Nandu Deleted.
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 3 Enter your name:Arvind Enter the id:M1 Added
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 3 Enter your name:Karthik Enter the id:M3 Added
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER
4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 4 Enter the member id:M3 Terminated
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 3 Enter your name:Karthik Enter the id:M2 This ID is already given to another member
1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 5 Enter the member id:M2 Enter the book name:App Chem Enter the author's name:Jain Enter the day of issue:16 Enter the month of issue:3 Enter the year of issue:2008
What do you want to do? 1.ADD A BOOK 2.DELETE A BOOK 3.ADD A MEMBER 4.TERMINATE A MEMBER 5.ISSUE A BOOK 6.RETURN A BOOK 7.ACCEPT FINE 6
Enter the book name:App Chem Enter the author name:Jain Enter the member ID:M2 Have you lost the issued book?n Enter the day of return:21 Enter the month of return:3 Enter the year of return:2008 Your fine is:0.0
*/