diff --git a/library2 - Copy (2)/library2.iml b/library2 - Copy (2)/library2.iml new file mode 100644 index 0000000..9465dd8 --- /dev/null +++ b/library2 - Copy (2)/library2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/library2 - Copy (2)/out/production/library2/Book.class b/library2 - Copy (2)/out/production/library2/Book.class new file mode 100644 index 0000000..a6d9773 Binary files /dev/null and b/library2 - Copy (2)/out/production/library2/Book.class differ diff --git a/library2 - Copy (2)/out/production/library2/Librarian.class b/library2 - Copy (2)/out/production/library2/Librarian.class new file mode 100644 index 0000000..855773c Binary files /dev/null and b/library2 - Copy (2)/out/production/library2/Librarian.class differ diff --git a/library2 - Copy (2)/out/production/library2/Library.class b/library2 - Copy (2)/out/production/library2/Library.class new file mode 100644 index 0000000..3863171 Binary files /dev/null and b/library2 - Copy (2)/out/production/library2/Library.class differ diff --git a/library2 - Copy (2)/out/production/library2/Main.class b/library2 - Copy (2)/out/production/library2/Main.class new file mode 100644 index 0000000..83d22ac Binary files /dev/null and b/library2 - Copy (2)/out/production/library2/Main.class differ diff --git a/library2 - Copy (2)/out/production/library2/User.class b/library2 - Copy (2)/out/production/library2/User.class new file mode 100644 index 0000000..b5280a3 Binary files /dev/null and b/library2 - Copy (2)/out/production/library2/User.class differ diff --git a/library2 - Copy (2)/out/production/library2/users.class b/library2 - Copy (2)/out/production/library2/users.class new file mode 100644 index 0000000..aee765f Binary files /dev/null and b/library2 - Copy (2)/out/production/library2/users.class differ diff --git a/library2 - Copy (2)/src/Book.java b/library2 - Copy (2)/src/Book.java new file mode 100644 index 0000000..add791c --- /dev/null +++ b/library2 - Copy (2)/src/Book.java @@ -0,0 +1,33 @@ +import java.util.Scanner; + +public class Book { + + public int isbn; + public String bookName; + public String authorName; + public String publishYear; + public int bookQty; + public int bookQtyCopy; + + Scanner input = new Scanner(System.in); + + public Book() + { + System.out.println("Enter Serial No of Book:"); + this.isbn = input.nextInt(); + input.nextLine(); + + System.out.println("Enter Book Name:"); + this.bookName = input.nextLine(); + + System.out.println("Enter Author Name:"); + this.authorName = input.nextLine(); + + System.out.println("Enter publish year:"); + this.publishYear = input.nextLine(); + + System.out.println("Enter Quantity of Books:"); + this.bookQty = input.nextInt(); + bookQtyCopy = this.bookQty; + } +} diff --git a/library2 - Copy (2)/src/Librarian.java b/library2 - Copy (2)/src/Librarian.java new file mode 100644 index 0000000..208dca4 --- /dev/null +++ b/library2 - Copy (2)/src/Librarian.java @@ -0,0 +1,20 @@ +import java.util.Scanner; + +public class Librarian { + + String libName; + String libPass; + Scanner input = new Scanner(System.in); + + public Librarian() + { + System.out.println("Enter librarian name:"); + + this.libName = input.nextLine(); + + System.out.println("Enter librarian password:"); + + this.libPass = input.nextLine(); + } + +} diff --git a/library2 - Copy (2)/src/Library.java b/library2 - Copy (2)/src/Library.java new file mode 100644 index 0000000..ede40e2 --- /dev/null +++ b/library2 - Copy (2)/src/Library.java @@ -0,0 +1,229 @@ +import java.util.Scanner; + +public class Library { + + public int BOOKcapacity; + Book theBooks[] = new Book[BOOKcapacity]; + + + public static int count; + + Scanner input = new Scanner(System.in); + + public void askingForBookCapacity(){ + + System.out.println("PLEASE ENTER THE CAPACITY OF YOUR LIBRARY FOR ADDING BOOKS"); + + BOOKcapacity = input.nextInt(); + } + + + public int compareBookObjects(Book b1, Book b2){ + + if (b1.bookName.equalsIgnoreCase(b2.bookName)){ + + System.out.println("Book of this Name Already Exists."); + + return 0; + + } + + if (b1.isbn == b2.isbn){ + + System.out.println("Book of this Serial No Already Exists."); + + return 0; + + } + + return 1; + + } + + + public void addBook(Book b) { + + for (int i = 0; i < count; i++) { + + if (this.compareBookObjects(b, this.theBooks[i]) == 0) + + return; + } + + if (count < BOOKcapacity){ + + theBooks[count] = b; + + count++; + } + + else{ + + System.out.println("No Space to Add More Books."); + } + + } + + public void searchByISBN(){ + + System.out.println("SEARCH BY SERIAL NUMBER"); + + int ISBN; + + System.out.println("Enter ISBN of Book:"); + + ISBN = input.nextInt(); + + int flag = 0; + + System.out.println("ISBN - Name - Author - Available Qty - Total Qty - publish year"); + + for (int i = 0; i < count; i++){ + + if (ISBN == theBooks[i].isbn){ + + System.out.println(theBooks[i].isbn + "\t\t" + theBooks[i].bookName + "\t\t" + theBooks[i].authorName + "\t\t" + theBooks[i].bookQtyCopy + "\t\t" + theBooks[i].bookQty + "\t\t" + theBooks[i].publishYear); + + flag++; + + } + } + + if (flag == 0){ + + System.out.println("No Book for ISBN " + ISBN + " Found."); + } + + } + + + public void searchByAuthorName(){ + + System.out.println("SEARCH BY AUTHOR'S NAME"); + + System.out.println("Enter Author Name:"); + + String authorName = input.nextLine(); + + int flag = 0; + + System.out.println("ISBN - Name - Author - Available Qty - Total Qty - publish year"); + + for (int i = 0; i < count; i++) { + + if (authorName.equalsIgnoreCase(theBooks[i].authorName)){ + + System.out.println(theBooks[i].isbn + "\t\t" + theBooks[i].bookName + "\t\t" + theBooks[i].authorName + "\t\t" + theBooks[i].bookQtyCopy + "\t\t" + theBooks[i].bookQty + "\t\t" + theBooks[i].publishYear); + + flag++; + + } + + } + + + if (flag == 0){ + + System.out.println("No Books of " + authorName + " Found."); + } + + } + + public void showAllBooks(){ + + System.out.println("SHOWING ALL BOOKS"); + + System.out.println("ISBN - Name - Author - Available Qty - Total Qty - publish year"); + + for (int i = 0; i < count; i++) { + + System.out.println(theBooks[i].isbn + "\t\t" + theBooks[i].bookName + "\t\t" + theBooks[i].authorName + "\t\t" + theBooks[i].bookQtyCopy + "\t\t" + theBooks[i].bookQty + "\t\t" + theBooks[i].publishYear); + + } + + } + + + public void changeBookQty(){ + + System.out.println("CHANGE QUANTITY OF A BOOK\n"); + + System.out.println("Enter ISBN of Book"); + + int ISBN = input.nextInt(); + + for (int i = 0; i < count; i++){ + + if (ISBN == theBooks[i].isbn){ + + System.out.println("Enter Number of Books to be Added or Removed \n ATTENTION: if you want to increase just type a positive number like \n2 and if you want to decrease write a negative number like -2 "); + + int addingQty = input.nextInt(); + + theBooks[i].bookQty += addingQty; + + theBooks[i].bookQtyCopy += addingQty; + + return; + } + } + } + + public int doesBookExists(int ISBN){ + + for (int i = 0; i < count; i++){ + + if (ISBN == theBooks[i].isbn){ + + if (theBooks[i].bookQtyCopy > 0){ + + System.out.println("Book exists."); + + return i; + } + + System.out.println("Book does not exist"); + + return -1; + } + } + + System.out.println("No Book of ISBN " + " Available in Library."); + + return -1; + } + + + public Book removeBook(){ + + System.out.println("Enter ISBN of Book to be Checked Out."); + + int ISBN = input.nextInt(); + + int bookIndex = doesBookExists(ISBN); + + if (bookIndex != -1){ + + theBooks[bookIndex].bookQtyCopy--; + + return theBooks[bookIndex]; + + } + + return null; + + } + + + public void returnBook(Book b){ + + for (int i = 0; i < count; i++){ + + if (b.equals(theBooks[i])){ + + theBooks[i].bookQtyCopy++; + + } + } + } +} \ No newline at end of file diff --git a/library2 - Copy (2)/src/Main.java b/library2 - Copy (2)/src/Main.java new file mode 100644 index 0000000..d79c593 --- /dev/null +++ b/library2 - Copy (2)/src/Main.java @@ -0,0 +1,129 @@ +import java.util.Scanner; + +public class Main { + + + public static void main(String[] args){ + + Scanner input = new Scanner(System.in); + + + System.out.println("**********************************************************************"); + System.out.println(" WELLCOME TO THE LIBRARY "); + System.out.println("**********************************************************************"); + + + + Library ob = new Library(); + + users obUser = new users(); + + Library bookCapacity = new Library(); + + bookCapacity.askingForBookCapacity(); + + users usersCapacity = new users(); + + usersCapacity.askingForUsersCapacity(); + + int choice; + + int searchChoice; + + do { + + dispMenu(); + + choice = input.nextInt(); + + + switch (choice) { + + + case 1: + Book b = new Book(); + ob.addBook(b); + break; + + + case 2: + ob.changeBookQty(); + break; + + + case 3: + + System.out.println(" press 1 to Search with Book Serial No."); + System.out.println(" Press 2 to Search with Book's Author Name."); + searchChoice = input.nextInt(); + + + switch (searchChoice) { + + + case 1: + ob.searchByISBN(); + break; + + + case 2: + ob.searchByAuthorName(); + } + + break; + + + case 4: + ob.showAllBooks(); + break; + + + case 5: + User s = new User(); + obUser. addUsers(s); + break; + + + case 6: + obUser.showAllUsers(); + break; + + + case 7: + obUser.rentBook(ob); + break; + + + case 8: + obUser.returnBook(ob); + break; + + + default: + + System.out.println("Thanks for Choosing Us !"); + } + + } + + + while (choice != 0); + } + + static void dispMenu(){ + + // Displaying menu + System.out.println("----------------------------------------------------------------------------------------------------------"); + System.out.println("Press 1 to Add new Book."); + System.out.println("Press 2 to Change Quantity of a Book."); + System.out.println("Press 3 to Search a Book."); + System.out.println("Press 4 to Show All Books."); + System.out.println("Press 5 to Register user."); + System.out.println("Press 6 to Show All Registered users."); + System.out.println("Press 7 to Borrow or Remove Book. "); + System.out.println("Press 8 to Return Book"); + System.out.println("Press 0 to Exit Application."); + System.out.println("-------------------------------------------------------------------------------------------------------"); + } + +} diff --git a/library2 - Copy (2)/src/User.java b/library2 - Copy (2)/src/User.java new file mode 100644 index 0000000..0b0e538 --- /dev/null +++ b/library2 - Copy (2)/src/User.java @@ -0,0 +1,23 @@ +import java.util.Scanner; + +public class User { + + String userName; + String passWord; + + Book borrowedBooks[] = new Book[3]; + public int booksCount = 0; + + Scanner input = new Scanner(System.in); + + public User() + { + System.out.println("Enter username:"); + + this.userName = input.nextLine(); + + System.out.println("Enter password:"); + + this.passWord = input.nextLine(); + } +} diff --git a/library2 - Copy (2)/src/users.java b/library2 - Copy (2)/src/users.java new file mode 100644 index 0000000..5fc39e5 --- /dev/null +++ b/library2 - Copy (2)/src/users.java @@ -0,0 +1,162 @@ + +import java.util.Scanner; + +public class users { + + public int USERcapacity; + + User theUsers[] = new User[USERcapacity]; + Scanner input = new Scanner(System.in); + + public static int count = 0; + + + public void askingForUsersCapacity(){ + + System.out.println("PLEASE ENTER THE CAPACITY OF YOUR LIBRARY FOR USERS"); + + USERcapacity = input.nextInt(); + } + public void addUsers(User u){ + + for (int i = 0; i < count; i++) { + + if (u.passWord.equalsIgnoreCase(theUsers[i].passWord)){ + + System.out.println("password " + u.passWord + " is Already Registered."); + + return; + } + } + + if (count <= USERcapacity){ + + theUsers[count] = u; + + count++; + } + } + + public void showAllUsers() { + + System.out.println("username----password"); + + for (int i = 0; i < count; i++){ + + System.out.println(theUsers[i].userName + " " + theUsers[i].passWord); + + } + + } + + public int doesUserExist(){ + + System.out.println("Enter password:"); + + String pass = input.nextLine(); + + for (int i = 0; i < count; i++){ + + if (theUsers[i].passWord.equalsIgnoreCase(pass)){ + + return i; + + } + + } + + + System.out.println("user is not Registered."); + + System.out.println("Get Registered First."); + + return -1; + } + + + public void rentBook(Library book){ + + int userIndex = this.doesUserExist(); + + if (userIndex != -1){ + + System.out.println("renting..."); + + book.showAllBooks(); + + Book b = book.removeBook(); + + System.out.println("renting..."); + + if (b != null){ + + if (theUsers[userIndex].booksCount <= 3){ + + System.out.println("adding book"); + + theUsers[userIndex].borrowedBooks[theUsers[userIndex].booksCount] = b; + + theUsers[userIndex].booksCount++; + + return; + + } + + else{ + + System.out.println("user Can not Borrow more than 3 Books."); + + return; + + } + + } + + System.out.println("Book is not Available."); + } + + + } + + public void returnBook(Library book){ + + int userIndex = this.doesUserExist(); + + if (userIndex != -1){ + + System.out.println("ISBN Book Name Author Name"); + + User u = theUsers[userIndex]; + + for (int i = 0; i < u.booksCount; i++){ + + System.out.println(u.borrowedBooks[i].isbn + "\t\t\t" + u.borrowedBooks[i].bookName + "\t\t\t" + u.borrowedBooks[i].authorName); + + } + + System.out.println("Enter ISBN of Book to be Checked In:"); + + int ISBN = input.nextInt(); + + for (int i = 0; i < u.booksCount; i++){ + + if (ISBN == u.borrowedBooks[i].isbn){ + + book.returnBook(u.borrowedBooks[i]); + + u.borrowedBooks[i] = null; + + return; + + } + + + } + + System.out.println("Book of ISBN " + ISBN + "not Found"); + + } + + } + +}