From 332f2b403816977e88517c4f78a6d511210c11c7 Mon Sep 17 00:00:00 2001 From: HalehQadyani <125292407+HalehQadyani@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:53:17 +0330 Subject: [PATCH 1/4] Update Librarian.java --- src/main/java/Librarian.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/Librarian.java b/src/main/java/Librarian.java index 321ce3a..da55128 100644 --- a/src/main/java/Librarian.java +++ b/src/main/java/Librarian.java @@ -1,3 +1,6 @@ +import java.util.HashMap; +import java.util.Map; + public class Librarian { /* * The librarian should have a username and a password @@ -6,5 +9,9 @@ public class Librarian { _ librarian and add\remove\update book */ - + private String Username; + private String Password; + Map Users = new HashMap(); + Map Librarians = new HashMap(); + } From e3e3483d84fb6b3e94d1b8ee2883a55fc9017ded Mon Sep 17 00:00:00 2001 From: HalehQadyani <125292407+HalehQadyani@users.noreply.github.com> Date: Wed, 8 Mar 2023 11:48:14 +0330 Subject: [PATCH 2/4] first commit --- src/main/java/Book.java | 21 ++++++- src/main/java/Librarian.java | 20 ++----- src/main/java/Library.java | 58 ++++++++++++++------ src/main/java/Main.java | 103 ++++++++++++++++++++++++++++++++--- src/main/java/User.java | 13 ++++- 5 files changed, 176 insertions(+), 39 deletions(-) diff --git a/src/main/java/Book.java b/src/main/java/Book.java index 7cff6f8..6453fec 100644 --- a/src/main/java/Book.java +++ b/src/main/java/Book.java @@ -1,3 +1,22 @@ public class Book { //Book should contain name,author,year of publish and ISBN -} + private String bookName; + private String author; + private int year; + private int ISBN; + + public Book(String bookName, String author, int year, int ISBN) { + this.bookName = bookName; + this.author = author; + this.year = year; + this.ISBN = ISBN; + } + + public String getNameOfBook() { + return this.bookName + ""; + } + + public int getNumberOfBook() { + return this.ISBN; + } +} \ No newline at end of file diff --git a/src/main/java/Librarian.java b/src/main/java/Librarian.java index da55128..9568060 100644 --- a/src/main/java/Librarian.java +++ b/src/main/java/Librarian.java @@ -1,17 +1,9 @@ -import java.util.HashMap; -import java.util.Map; - public class Librarian { - /* - * The librarian should have a username and a password - * The librarian should be able to search users, librarians and books - * The librarian should be able to add\remove\update user add\remove\update_ - _ librarian and add\remove\update book - */ + private String username; + private String password; - private String Username; - private String Password; - Map Users = new HashMap(); - Map Librarians = new HashMap(); - + public Librarian(String username, String password){ + this.username = username; + this.password = password; + } } diff --git a/src/main/java/Library.java b/src/main/java/Library.java index 6c34354..24c3cfc 100644 --- a/src/main/java/Library.java +++ b/src/main/java/Library.java @@ -1,3 +1,7 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + public class Library { /* * The library should have a list of books. @@ -6,25 +10,49 @@ public class Library { * The library should have a list of users and a list of librarians. */ + private String libraryName; + + //book + ArrayList ExistedBooks = new ArrayList(); + Map NumberOfBooks = new HashMap(); + + //librarian user + ArrayList Users = new ArrayList(); + ArrayList Librarians = new ArrayList(); + Map users = new HashMap(); + Map librarians = new HashMap(); + + public Library(String libraryName) { + this.libraryName = libraryName; + } + //book related functions - public void addBook(){ - //TODO + public void addBook(Book book){ + ExistedBooks.add(book.getNameOfBook()); + NumberOfBooks.put(book.getNameOfBook(), book.getNumberOfBook()); } - public void removeBook(){ - //TODO + public void removeBook(Book book){ + } - public void searchBook(){ - //TODO + public boolean doesBookExist(String bookName) { + for (String element : ExistedBooks) { + if (element.contains(bookName)) { + return true; + } else { + System.out.println("This book doesn't exist!"); + } + } + return false; } - public void updateBook(){ + public void searchBook(){ //TODO } - public void doesBookExist(){ + public void updateBook(){ //TODO } @@ -46,15 +74,15 @@ public void removeUser(){ //TODO } - public void searchUser(){ + public void doesUserExist(){ //TODO } - public void updateUser(){ + public void searchUser(){ //TODO } - public void doesUserExist(){ + public void updateUser(){ //TODO } @@ -68,17 +96,15 @@ public void removeLibrarian(){ //TODO } - public void searchLibrarian(){ + public void doesLibrarianExist(){ //TODO } - public void updateLibrarian(){ + public void searchLibrarian(){ //TODO } - public void doesLibrarianExist(){ + public void updateLibrarian(){ //TODO } - - } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 9a347d3..8ecbbb2 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -2,17 +2,106 @@ public class Main { /* - * make a functional library app using oop - * run the main program in Main.java and code the oop part in other classes - * don't forget to add at least 1 librarian to the library to make it functionable. - * * *** don't limit yourself to our template *** + * make a functional library app using oop + * run the main program in Main.java and code the oop part in other classes + * don't forget to add at least 1 librarian to the library to make it functionable. + * * *** don't limit yourself to our template *** */ - public static void main(String[] args) { + private static Library library = new Library("sun"); + private static Librarian firstLibrarian = new Librarian("firstLibrarian", "0000"); + private static Book firstBook = new Book("Harry Potter", "J. K. Rowling", 1997, 2); + public static void main(String[] args){ + int option, ex; + do + { + try (Scanner sc = new Scanner(System.in);) { + System.out.println("Enter your choice from the following menu:"); + System.out.println("1.User 2.Librarian 3.Exit"); + option = sc.nextInt(); + if(option != 3){ + System.out.println("Username: "); + String username = sc.next(); + System.out.println(username); + System.out.println("Password: "); + String password = sc.next(); + System.out.println(password); + //check username and password + } + else + break; + runMenu(option); + } + }while(true); } - public static void runMenu(){ - //TODO: + + public static void runMenu(int choice){ + if (choice == 1) { + int option, ex; + do + { + try (Scanner sc = new Scanner(System.in)) { + System.out.println("Enter your choice from the following menu:"); + System.out.println("1.Rent Book 2.Return Book 3.Exit"); + option = sc.nextInt(); + if(option == 1){ + //call rent function + } else if (option == 2) { + //call return function + } else { + break; + } + System.out.println("Do you want to continue? 1.Yes 2.No"); + ex=sc.nextInt(); + } + }while(ex==1); + } else if (choice == 2) { + int option, ex; + do + { + try (Scanner sc = new Scanner(System.in)) { + System.out.println("Enter your choice from the following menu:"); + System.out.println("1.Add Book 2.Remove Book 3.Search Book"); + System.out.println("4.Add User 5.Remove User 6.Search User"); + System.out.println("7.Add Librarian 8.Remove librarian 9.Search Librarian"); + option = sc.nextInt(); + if(option == 1){ + System.out.println("Book name: "); + String bookName = sc.next(); + System.out.println("Author name: "); + String authorName = sc.next(); + System.out.println("Year of publish: "); + int Year = sc.nextInt(); + System.out.println("ISBN: "); + int ISBN = sc.nextInt(); + Book newBook = new Book(bookName, authorName, Year, ISBN); + library.addBook(newBook); + } else if (option == 2) { + //call remove book + } else if (option == 3) { + //call search book + } else if (option == 4) { + //call add user + } else if (option == 5) { + //call remove user + } else if (option == 6) { + //call search user + } else if (option == 7) { + //call add librarian + } else if (option == 8) { + //call remove librarian + } else if (option == 9) { + //call search librarian + } + else { + break; + } + System.out.println("Do you want to continue? 1.Yes 2.No"); + ex=sc.nextInt(); + } + }while(ex==1); + } } } diff --git a/src/main/java/User.java b/src/main/java/User.java index dbe4020..0d5af7a 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -1,7 +1,18 @@ +import java.util.ArrayList; + public class User { //User should have a list of books //User should have a username and a password + ArrayList rentedBooks = new ArrayList(); + private String username; + private String password; + + public User(String username, String password){ + this.username = username; + this.password = password; + } + public void rentBook(){ //TODO } @@ -9,4 +20,4 @@ public void rentBook(){ public void returnBook(){ //TODO } -} +} \ No newline at end of file From ec238728f343a973fb1abaa548f51567123e80be Mon Sep 17 00:00:00 2001 From: HalehQadyani <125292407+HalehQadyani@users.noreply.github.com> Date: Wed, 8 Mar 2023 22:57:31 +0330 Subject: [PATCH 3/4] second commit --- src/main/java/Librarian.java | 8 ++ src/main/java/Library.java | 168 +++++++++++++++++++++-------- src/main/java/Main.java | 204 ++++++++++++++++++++++------------- src/main/java/User.java | 8 ++ 4 files changed, 271 insertions(+), 117 deletions(-) diff --git a/src/main/java/Librarian.java b/src/main/java/Librarian.java index 9568060..14049ce 100644 --- a/src/main/java/Librarian.java +++ b/src/main/java/Librarian.java @@ -6,4 +6,12 @@ public Librarian(String username, String password){ this.username = username; this.password = password; } + + public String getUsername() { + return this.username; + } + + public String getPassword() { + return this.password; + } } diff --git a/src/main/java/Library.java b/src/main/java/Library.java index 24c3cfc..f91a09e 100644 --- a/src/main/java/Library.java +++ b/src/main/java/Library.java @@ -11,21 +11,67 @@ public class Library { */ private String libraryName; + private String book = "Harry Potter"; + private int num = 2; + private String librarian = "firstLibrarian"; + private String User = "Haleh"; + private String pass = "0000"; + + private static Librarian firstLibrarian = new Librarian("firstLibrarian", "0000"); + private static Book firstBook = new Book("Harry Potter", "J. K. Rowling", 1997, 2); + private static User firstUser = new User("Haleh", "0000"); //book - ArrayList ExistedBooks = new ArrayList(); - Map NumberOfBooks = new HashMap(); + private ArrayList ExistedBooks; + private static Map NumberOfBooks; //librarian user - ArrayList Users = new ArrayList(); - ArrayList Librarians = new ArrayList(); - Map users = new HashMap(); - Map librarians = new HashMap(); + private static ArrayList Users = new ArrayList(); + private static ArrayList Librarians = new ArrayList(); + private static Map users = new HashMap(); + private static Map librarians; public Library(String libraryName) { this.libraryName = libraryName; + ExistedBooks = new ArrayList(); + ExistedBooks.add(book); + NumberOfBooks = new HashMap(); + NumberOfBooks.put(book, num); + + Librarians = new ArrayList(); + Librarians.add(firstLibrarian); + librarians = new HashMap(); + librarians.put(librarian, pass); + + Users = new ArrayList(); + Users.add(firstUser); + users = new HashMap(); + users.put(User, pass); + } + + public ArrayList getExistedBooks() { + return ExistedBooks; + } + + public Map getNumberOfBooks() { + return NumberOfBooks; + } + + public ArrayList getLibrarians() { + return Librarians; } + public Map getlibrarians() { + return librarians; + } + + public ArrayList getUsers() { + return Users; + } + + public Map getusers() { + return users; + } //book related functions public void addBook(Book book){ @@ -33,8 +79,14 @@ public void addBook(Book book){ NumberOfBooks.put(book.getNameOfBook(), book.getNumberOfBook()); } - public void removeBook(Book book){ - + public void removeBook(String bookName){ + if(doesBookExist(bookName)) { + ExistedBooks.remove(bookName); + NumberOfBooks.remove(bookName); + System.out.println(bookName + " is removed!"); + } else { + System.out.println("This book doesn't exist!"); + } } public boolean doesBookExist(String bookName) { @@ -48,63 +100,95 @@ public boolean doesBookExist(String bookName) { return false; } - public void searchBook(){ - //TODO - } - - public void updateBook(){ - //TODO - } - - public void increaseBook(){ - //TODO - } - - public void decreaseBook(){ - //TODO + public void searchBook(String bookName){ + if(doesBookExist(bookName)) { + System.out.println("We have " + bookName); + } else { + System.out.println("No book with name " + bookName); + } } //user related functions - public void addUser(){ - //TODO + public void addUser(User user){ + Users.add(user); + users.put(user.getUsername(), user.getPassword()); } - public void removeUser(){ - //TODO + public void removeUser(User user){ + if(doesUserExist(user)) { + Users.remove(user); + users.remove(user.getUsername()); + System.out.println(user.getUsername() + " is removed!"); + } else { + System.out.println("This book doesn't exist!"); + } } - public void doesUserExist(){ - //TODO + public boolean doesUserExist(User user){ + if(users.containsKey(user.getUsername()) && users.containsValue(user.getPassword())){ + return true; + } else { + System.out.println("No member in the list!"); + } + return false; } - public void searchUser(){ - //TODO + public void searchUser(User user){ + if(doesUserExist(user)) { + System.out.println(user.getUsername() + " exists"); + } else { + System.out.println("No member with username " + user.getUsername()); + } } - public void updateUser(){ - //TODO + public void loginUser(User user){ + if(doesUserExist(user)) { + System.out.println("Hello " + user.getUsername()); + } else { + System.out.println("No member with username " + user.getUsername()); + } } //librarian related functions - public void addLibrarian(){ - //TODO + public void addLibrarian(Librarian librarian){ + Librarians.add(librarian); + librarians.put(librarian.getUsername(), librarian.getPassword()); } - public void removeLibrarian(){ - //TODO + public void removeLibrarian(Librarian librarian){ + if(doesLibrarianExist(librarian)) { + Librarians.remove(librarian); + librarians.remove(librarian.getUsername()); + System.out.println(librarian.getUsername() + " is removed!"); + } else { + System.out.println("This librarian doesn't exist!"); + } } - public void doesLibrarianExist(){ - //TODO + public boolean doesLibrarianExist(Librarian librarian){ + if(librarians.containsKey(librarian.getUsername()) && librarians.containsValue(librarian.getPassword())){ + return true; + } else { + System.out.println("No librarian in the list!"); + } + return false; } - public void searchLibrarian(){ - //TODO + public void searchLibrarian(Librarian librarian){ + if(doesLibrarianExist(librarian)) { + System.out.println(librarian.getUsername() + " exists"); + } else { + System.out.println("No member with username " + librarian.getUsername()); + } } - public void updateLibrarian(){ - //TODO + public void loginLibrarian(Librarian librarian){ + if(doesLibrarianExist(librarian)) { + System.out.println("Hello " + librarian.getUsername()); + } else { + System.out.println("No member with username " + librarian.getUsername()); + } } } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 8ecbbb2..8bf6190 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,4 +1,6 @@ import java.util.Scanner; +import java.util.ArrayList; +import java.util.Map; public class Main { /* @@ -8,100 +10,152 @@ public class Main { * * *** don't limit yourself to our template *** */ + private static Scanner sc = new Scanner(System.in); private static Library library = new Library("sun"); + //librarian private static Librarian firstLibrarian = new Librarian("firstLibrarian", "0000"); private static Book firstBook = new Book("Harry Potter", "J. K. Rowling", 1997, 2); + private static User firstUser = new User("Haleh", "0000"); + + ArrayList ExistedBooks = library.getExistedBooks(); + Map NumberOfBooks = library.getNumberOfBooks(); + ArrayList Librarians = library.getLibrarians(); + Map librarians = library.getlibrarians(); + ArrayList Users = library.getUsers(); + Map users = library.getusers(); public static void main(String[] args){ - int option, ex; do - { - try (Scanner sc = new Scanner(System.in);) { - System.out.println("Enter your choice from the following menu:"); + { System.out.println("Enter your choice from the following menu:"); System.out.println("1.User 2.Librarian 3.Exit"); - option = sc.nextInt(); - if(option != 3){ + int choice; + choice = sc.nextInt(); + if(choice == 1){ System.out.println("Username: "); String username = sc.next(); System.out.println(username); System.out.println("Password: "); String password = sc.next(); System.out.println(password); - //check username and password - } - else - break; - runMenu(option); + User newUser = new User(username, password); + if(library.doesUserExist(newUser)){ + library.loginUser(newUser); + } else { + break; + } } + else if(choice == 2){ + System.out.println("Username: "); + String username = sc.next(); + System.out.println(username); + System.out.println("Password: "); + String password = sc.next(); + System.out.println(password); + Librarian newLibrarian = new Librarian(username, password); + if(library.doesLibrarianExist(newLibrarian)){ + library.loginLibrarian(newLibrarian); + } else { + break; + } + } + else { + break; + } + runMenu(choice); }while(true); } - public static void runMenu(int choice){ - if (choice == 1) { - int option, ex; - do - { - try (Scanner sc = new Scanner(System.in)) { - System.out.println("Enter your choice from the following menu:"); - System.out.println("1.Rent Book 2.Return Book 3.Exit"); - option = sc.nextInt(); - if(option == 1){ - //call rent function - } else if (option == 2) { - //call return function - } else { - break; - } - System.out.println("Do you want to continue? 1.Yes 2.No"); - ex=sc.nextInt(); + public static void runMenu(int choice) { + int ex = 0; + do { + int option; + if (choice == 1) { + System.out.println("Enter your choice from the following menu:"); + System.out.println("1.Rent Book 2.Return Book 3.Exit"); + option = sc.nextInt(); + if (option == 1) { + //call rent function + } else if (option == 2) { + //call return function + } else { + break; } - }while(ex==1); - } else if (choice == 2) { - int option, ex; - do - { - try (Scanner sc = new Scanner(System.in)) { - System.out.println("Enter your choice from the following menu:"); - System.out.println("1.Add Book 2.Remove Book 3.Search Book"); - System.out.println("4.Add User 5.Remove User 6.Search User"); - System.out.println("7.Add Librarian 8.Remove librarian 9.Search Librarian"); - option = sc.nextInt(); - if(option == 1){ - System.out.println("Book name: "); - String bookName = sc.next(); - System.out.println("Author name: "); - String authorName = sc.next(); - System.out.println("Year of publish: "); - int Year = sc.nextInt(); - System.out.println("ISBN: "); - int ISBN = sc.nextInt(); - Book newBook = new Book(bookName, authorName, Year, ISBN); - library.addBook(newBook); - } else if (option == 2) { - //call remove book - } else if (option == 3) { - //call search book - } else if (option == 4) { - //call add user - } else if (option == 5) { - //call remove user - } else if (option == 6) { - //call search user - } else if (option == 7) { - //call add librarian - } else if (option == 8) { - //call remove librarian - } else if (option == 9) { - //call search librarian - } - else { - break; - } - System.out.println("Do you want to continue? 1.Yes 2.No"); - ex=sc.nextInt(); + System.out.println("Do you want to continue? 1.Yes 2.No"); + ex = sc.nextInt(); + } else if (choice == 2) { + System.out.println("Enter your choice from the following menu:"); + System.out.println("1.Add Book 2.Remove Book 3.Search Book"); + System.out.println("4.Add User 5.Remove User 6.Search User"); + System.out.println("7.Add Librarian 8.Remove librarian 9.Search Librarian"); + option = sc.nextInt(); + if (option == 1) { + System.out.println("Book name: "); + String bookName = sc.next(); + System.out.println("Author name: "); + String authorName = sc.next(); + System.out.println("Year of publish: "); + int Year = sc.nextInt(); + System.out.println("ISBN: "); + int ISBN = sc.nextInt(); + Book newBook = new Book(bookName, authorName, Year, ISBN); + library.addBook(newBook); + } else if (option == 2) { + System.out.println("Book name: "); + String bookName = sc.next(); + library.removeBook(bookName); + } else if (option == 3) { + System.out.println("Book name: "); + String bookName = sc.next(); + library.searchBook(bookName); + } else if (option == 4) { + System.out.println("Username: "); + String username = sc.next(); + System.out.println("Password: "); + String password = sc.next(); + User newUser = new User(username, password); + library.addUser(newUser); + } else if (option == 5) { + System.out.println("Username: "); + String username = sc.next(); + System.out.println("Password: "); + String password = sc.next(); + User newUser = new User(username, password); + library.removeUser(newUser); + } else if (option == 6) { + System.out.println("Username: "); + String username = sc.next(); + System.out.println("Password: "); + String password = sc.next(); + User newUser = new User(username, password); + library.searchUser(newUser); + } else if (option == 7) { + System.out.println("Username: "); + String username = sc.next(); + System.out.println("Password: "); + String password = sc.next(); + Librarian newLibrarian = new Librarian(username, password); + library.addLibrarian(newLibrarian); + } else if (option == 8) { + System.out.println("Username: "); + String username = sc.next(); + System.out.println("Password: "); + String password = sc.next(); + Librarian newLibrarian = new Librarian(username, password); + library.removeLibrarian(newLibrarian); + } else if (option == 9) { + System.out.println("Username: "); + String username = sc.next(); + System.out.println("Password: "); + String password = sc.next(); + Librarian newLibrarian = new Librarian(username, password); + library.searchLibrarian(newLibrarian); + } else { + break; } - }while(ex==1); - } + System.out.println("Do you want to continue? 1.Yes 2.No"); + ex = sc.nextInt(); + } + } while (ex == 1); } } diff --git a/src/main/java/User.java b/src/main/java/User.java index 0d5af7a..b042bcd 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -13,6 +13,14 @@ public User(String username, String password){ this.password = password; } + public String getUsername() { + return this.username; + } + + public String getPassword() { + return this.password; + } + public void rentBook(){ //TODO } From 1eaad48fbf9d6a24f4ec16023fe8789fd3450c3e Mon Sep 17 00:00:00 2001 From: HalehQadyani <125292407+HalehQadyani@users.noreply.github.com> Date: Thu, 9 Mar 2023 15:20:09 +0330 Subject: [PATCH 4/4] third commit --- src/main/java/Library.java | 27 +++++++++++++++++++++------ src/main/java/Main.java | 12 ++++++------ src/main/java/User.java | 21 +++++++++++++++------ 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/main/java/Library.java b/src/main/java/Library.java index f91a09e..7a76a5a 100644 --- a/src/main/java/Library.java +++ b/src/main/java/Library.java @@ -72,6 +72,9 @@ public ArrayList getUsers() { public Map getusers() { return users; } + + ArrayList rentedBooks = firstUser.getRentedBooks(); + //book related functions public void addBook(Book book){ @@ -90,12 +93,10 @@ public void removeBook(String bookName){ } public boolean doesBookExist(String bookName) { - for (String element : ExistedBooks) { - if (element.contains(bookName)) { - return true; - } else { - System.out.println("This book doesn't exist!"); - } + if(NumberOfBooks.containsKey(bookName) && NumberOfBooks.get(bookName) != 0){ + return true; + } else { + System.out.println("No book in the list!"); } return false; } @@ -108,6 +109,20 @@ public void searchBook(String bookName){ } } + public void rentBook(String book){ + if(doesBookExist(book)){ + NumberOfBooks.put(book, NumberOfBooks.get(book) - 1); + firstUser.rentBook(book); + } else { + System.out.println("Number of this book = 0"); + } + } + + public void returnBook(String book){ + NumberOfBooks.put(book, NumberOfBooks.get(book) + 1); + firstUser.returnBook(book); + } + //user related functions public void addUser(User user){ diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 8bf6190..2475fbc 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -33,10 +33,8 @@ public static void main(String[] args){ if(choice == 1){ System.out.println("Username: "); String username = sc.next(); - System.out.println(username); System.out.println("Password: "); String password = sc.next(); - System.out.println(password); User newUser = new User(username, password); if(library.doesUserExist(newUser)){ library.loginUser(newUser); @@ -47,10 +45,8 @@ public static void main(String[] args){ else if(choice == 2){ System.out.println("Username: "); String username = sc.next(); - System.out.println(username); System.out.println("Password: "); String password = sc.next(); - System.out.println(password); Librarian newLibrarian = new Librarian(username, password); if(library.doesLibrarianExist(newLibrarian)){ library.loginLibrarian(newLibrarian); @@ -75,9 +71,13 @@ public static void runMenu(int choice) { System.out.println("1.Rent Book 2.Return Book 3.Exit"); option = sc.nextInt(); if (option == 1) { - //call rent function + System.out.println("Book name: "); + String bookName = sc.next(); + library.rentBook(bookName); } else if (option == 2) { - //call return function + System.out.println("Book name: "); + String bookName = sc.next(); + library.returnBook(bookName); } else { break; } diff --git a/src/main/java/User.java b/src/main/java/User.java index b042bcd..493e2c9 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -1,16 +1,23 @@ import java.util.ArrayList; -public class User { +public class User { //User should have a list of books //User should have a username and a password - ArrayList rentedBooks = new ArrayList(); + String book = "0"; + ArrayList rentedBooks; private String username; private String password; public User(String username, String password){ this.username = username; this.password = password; + rentedBooks = new ArrayList(); + rentedBooks.add(book); + } + + public ArrayList getRentedBooks() { + return rentedBooks; } public String getUsername() { @@ -21,11 +28,13 @@ public String getPassword() { return this.password; } - public void rentBook(){ - //TODO + public void rentBook(String book){ + rentedBooks.add(book); + System.out.println("You've rented " + book); } - public void returnBook(){ - //TODO + public void returnBook(String book){ + rentedBooks.remove(book); + System.out.println("You've returned " + book); } } \ No newline at end of file