diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ac2ea36..2017c6a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,7 +5,15 @@ + + + + + + + + - { - "keyToString": { - "Application.MainApplication.executor": "Run", - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "git-widget-placeholder": "main", - "ignore.virus.scanning.warn.message": "true", - "kotlin-language-version-configured": "true", - "last_opened_file_path": "E:/ibrahem/oop/project4/New folder/library-system", - "project.structure.last.edited": "Libraries", - "project.structure.proportion": "0.15", - "project.structure.side.proportion": "0.2" + +}]]> + + + + + + + + + + + + + + + @@ -229,4 +253,30 @@ + + + + + file://$PROJECT_DIR$/src/main/java/com/asu/librarysystem/Library.java + 630 + + + file://$PROJECT_DIR$/src/main/java/com/asu/librarysystem/Library.java + 488 + + + file://$PROJECT_DIR$/src/main/java/com/asu/librarysystem/ReviewHandler.java + 68 + + + file://$PROJECT_DIR$/src/main/java/com/asu/librarysystem/ReviewHandler.java + 80 + + + + \ No newline at end of file diff --git a/data/covers/11.jpg b/data/covers/11.jpg index f67ac1a..1818948 100644 Binary files a/data/covers/11.jpg and b/data/covers/11.jpg differ diff --git a/data/covers/12.jpg b/data/covers/12.jpg index 1818948..7ea1ef8 100644 Binary files a/data/covers/12.jpg and b/data/covers/12.jpg differ diff --git a/data/datafiles/books_data.txt b/data/datafiles/books_data.txt new file mode 100644 index 0000000..276b739 --- /dev/null +++ b/data/datafiles/books_data.txt @@ -0,0 +1,20 @@ +10,,,1,,,Harry Potter and the Prisoner of Azkaban,,,J. K. Rowling,,,2023,,,true,,,200,,,4,,,Harry Potter and the Prisoner of Azkaban is a fantasy novel written by British author J. K. Rowling and is the third in the Harry Potter series. The book follows Harry Potter, a young wizard, in his third year at Hogwarts School of Witchcraft and Wizardry. Along with friends Ronald Weasley and Hermione Granger, Harry investigates Sirius Black, an escaped prisoner from Azkaban, the wizard prison, believed to be one of Lord Voldemort's old allies.,,,E:\ibrahem\oop\project6\1\library-system2\data\covers\1.jpg +HORROR,,, +10,,,2,,,Harry Potter and the Chamber of Secrets,,,J. K. Rowling,,,2020,,,true,,,200,,,3,,,Harry Potter and the Chamber of Secrets is a fantasy novel written by British author J. K. Rowling and the second novel in the Harry Potter series. The plot follows Harry's second year at Hogwarts School of Witchcraft and Wizardry, during which a series of messages on the walls of the school's corridors warn that the "Chamber of Secrets" has been opened and that the "heir of Slytherin" would kill all pupils who do not come from all-magical families. These threats are found after attacks that leave residents of the school petrified. Throughout the year, Harry and his friends Ron and Hermione investigate the attacks.,,,E:\ibrahem\oop\project6\1\library-system2\data\covers\2.jpg +ADVENTURE,,, +10,,,3,,,The Alchemist ,,,Paulo Coelho ,,,2021,,,true,,,200,,,1,,,The Alchemist (Portuguese: O Alquimista) is a novel by Brazilian author Paulo Coelho which was first published in 1988. Originally written in Portuguese, it became a widely translated international bestseller.[1][2] The story follows the shepherd boy Santiago in his journey across northern Africa to the pyramids of Egypt after he dreams of finding a treasure there.,,,E:\ibrahem\oop\project6\1\library-system2\data\covers\3.jpg +ADVENTURE,,, +10,,,4,,,A Tale of Two Cities,,,Charles Dickens,,,2023,,,true,,,200,,,4,,,A Tale of Two Cities is a historical novel published in 1859 by Charles Dickens, set in London and Paris before and during the French Revolution. The novel tells the story of the French Doctor Manette, his 18-year-long imprisonment in the Bastille in Paris, and his release to live in London with his daughter Lucie whom he had never met. The story is set against the conditions that led up to the French Revolution and the Reign of Terror.,,,E:\ibrahem\oop\project6\1\library-system2\data\covers\4.jpg +ADVENTURE,,, +10,,,5,,,The Little Prince ,,,Antoine de Saint-Exupéry,,,2020,,,true,,,200,,,2,,,The Little Prince (French: Le Petit Prince, pronounced [lə p(ə)ti pʁɛ̃s]) is a novella written and illustrated by French aristocrat, writer, and military pilot Antoine de Saint-Exupéry. It was first published in English and French in the United States by Reynal & Hitchcock in April 1943 and was published posthumously in France following liberation; Saint-Exupéry's works had been banned by the Vichy Regime. The story follows a young prince who visits various planets, including Earth, and addresses themes of loneliness, friendship, love, and loss. Despite its style as a children's book, The Little Prince makes observations about life, adults, and human nature.,,,E:\ibrahem\oop\project6\1\library-system2\data\covers\5.jpg +ADVENTURE,,, +10,,,6,,,Harry Potter and the Philosopher's Stone,,,J. K. Rowling,,,2021,,,true,,,200,,,2,,,Harry Potter and the Philosopher's Stone is a fantasy novel written by British author J. K. Rowling. The first novel in the Harry Potter series and Rowling's debut novel, it follows Harry Potter, a young wizard who discovers his magical heritage on his eleventh birthday, when he receives a letter of acceptance to Hogwarts School of Witchcraft and Wizardry. Harry makes close friends and a few enemies during his first year at the school and with the help of his friends, Ron Weasley and Hermione Granger, he faces an attempted comeback by the dark wizard Lord Voldemort, who killed Harry's parents, but failed to kill Harry when he was just 15 months old.,,,E:\ibrahem\oop\project6\1\library-system2\data\covers\6.jpg +ADVENTURE,,, +10,,,7,,,And Then There Were None,,,Agatha Christie,,,2023,,,true,,,200,,,4,,,And Then There Were None is a mystery novel by the English writer Agatha Christie, who described it as the most difficult of her books to write.[2] It was first published in the United Kingdom by the Collins Crime Club on 6 November 1939, as Ten Little Niggers,[3] after an 1869 minstrel song that serves as a major plot element.[4][5] The US edition was released in January 1940 with the title And Then There Were None, taken from the last five words of the song.[6] Successive American reprints and adaptations use that title, though American Pocket Books paperbacks used the title Ten Little Indians between 1964 and 1986. UK editions continued to use the original title until 1985.[7],,,E:\ibrahem\oop\project6\1\library-system2\data\covers\7.jpg +ADVENTURE,,, +10,,,8,,,The Hobbit,,,J. R. R. Tolkien,,,2020,,,true,,,200,,,3,,,The Hobbit, or There and Back Again is a children's fantasy novel by English author J. R. R. Tolkien. It was published in 1937 to wide critical acclaim, being nominated for the Carnegie Medal and awarded a prize from the New York Herald Tribune for best juvenile fiction. The book is recognized as a classic in children's literature and is one of the best-selling books of all time, with over 100 million copies sold.,,,E:\ibrahem\oop\project6\1\library-system2\data\covers\8.jpg +ADVENTURE,,,HORROR,,, +10,,,9,,,She: A History of Adventure,,,H. Rider Haggard,,,2021,,,true,,,200,,,1,,,She, subtitled A History of Adventure, is a novel by the English writer H. Rider Haggard, published in book form in 1887 following serialisation in The Graphic magazine between October 1886 and January 1887. She was extraordinarily popular upon its release and has never been out of print.,,,E:\ibrahem\oop\project6\1\library-system2\data\covers\9.jpg +ADVENTURE,,, +10,,,10,,,The Da Vinci Code,,,Dan Brown,,,2021,,,true,,,200,,,2,,,The Da Vinci Code is a 2003 mystery thriller novel by Dan Brown. It is Brown's second novel to include the character Robert Langdon: the first was his 2000 novel Angels & Demons. The Da Vinci Code follows symbologist Robert Langdon and cryptologist Sophie Neveu after a murder in the Louvre Museum in Paris causes them to become involved in a battle between the Priory of Sion and Opus Dei over the possibility of Jesus Christ and Mary Magdalene having had a child together.,,,E:\ibrahem\oop\project6\1\library-system2\data\covers\10.jpg +ADVENTURE,,, diff --git a/data/datafiles/borrowers_data.txt b/data/datafiles/borrowers_data.txt new file mode 100644 index 0000000..13d3f95 --- /dev/null +++ b/data/datafiles/borrowers_data.txt @@ -0,0 +1 @@ +5,,,3,,,user2,,,user2,,,111 diff --git a/data/datafiles/customers_data.txt b/data/datafiles/customers_data.txt new file mode 100644 index 0000000..5655a0c --- /dev/null +++ b/data/datafiles/customers_data.txt @@ -0,0 +1 @@ +5,,,2,,,user1,,,user1,,,111 diff --git a/data/datafiles/discount_data.txt b/data/datafiles/discount_data.txt new file mode 100644 index 0000000..e7bce7b --- /dev/null +++ b/data/datafiles/discount_data.txt @@ -0,0 +1,2 @@ +Lucky0,,,50.0 +Lucky1,,,100.0 diff --git a/data/datafiles/order_data_user1.txt b/data/datafiles/order_data_user1.txt new file mode 100644 index 0000000..5158d6e --- /dev/null +++ b/data/datafiles/order_data_user1.txt @@ -0,0 +1,5 @@ +5,,,1,,,1,,,2 +5,,,2,,,2,,,2 +5,,,3,,,3,,,1 +5,,,4,,,5,,,2 +5,,,5,,,7,,,2 diff --git a/data/datafiles/reviews_data.txt b/data/datafiles/reviews_data.txt new file mode 100644 index 0000000..bc7ba88 --- /dev/null +++ b/data/datafiles/reviews_data.txt @@ -0,0 +1,4 @@ +11,,,2,,,2,,,1,,,1,,,I don't love this book +11,,,4,,,2,,,10,,,3,,,I don't love this book +11,,,6,,,3,,,1,,,4,,,good +11,,,8,,,3,,,10,,,1,,,bad diff --git a/data/datafiles/transaction_data_user2.txt b/data/datafiles/transaction_data_user2.txt new file mode 100644 index 0000000..9a3b792 --- /dev/null +++ b/data/datafiles/transaction_data_user2.txt @@ -0,0 +1,3 @@ +3,,,3,,,3,,,3,,,2023-12-21,,,2024-01-21 +3,,,3,,,3,,,3,,,2023-12-21,,,2024-01-21 +3,,,3,,,3,,,3,,,2023-12-21,,,2024-01-21 diff --git a/src/main/java/com/asu/librarysystem/Account.java b/src/main/java/com/asu/librarysystem/Account.java index 2adeb0a..858c39e 100644 --- a/src/main/java/com/asu/librarysystem/Account.java +++ b/src/main/java/com/asu/librarysystem/Account.java @@ -18,6 +18,18 @@ public Account(String userName, String password, String phoneNumber) { } + public Account(int id, String userName, String password, String phoneNumber) { + this.id=id; + this.userName = userName; + this.Password = password; + this.phoneNumber = phoneNumber; + } + public void setIdCounter(int idCounter) { + this.idCounter=idCounter; + } + public int getIdCounter(){ + return idCounter; + } public void setPassword(String password) { Password = password; diff --git a/src/main/java/com/asu/librarysystem/Book.java b/src/main/java/com/asu/librarysystem/Book.java index f9a3215..9cb0326 100644 --- a/src/main/java/com/asu/librarysystem/Book.java +++ b/src/main/java/com/asu/librarysystem/Book.java @@ -21,8 +21,19 @@ public class Book { - public Book(String title, String author, int publicationYear, boolean status, int price, int quantity - , String description, String coverPath, Category[] categories) { + public Book(int id,String title, String author, int publicationYear, boolean status, int price, int quantity, String descreption, String coverPath, ArrayList categories){ + this.id=id; + this.title = title; + this.author = author; + this.publicationYear = publicationYear; + this.status = status; + this.price = price; + this.quantity = quantity; + this.description = descreption; + setCover(coverPath); + this.categories=categories; + } + public Book(String title, String author, int publicationYear, boolean status, int price, int quantity, String descreption, String coverPath){ this.id = ++idCounter; this.title = title; this.author = author; @@ -30,13 +41,21 @@ public Book(String title, String author, int publicationYear, boolean status, in this.status = status; this.price = price; this.quantity = quantity; - this.description = description; - + this.description = descreption; setCover(coverPath); + } + public Book(String title, String author, int publicationYear, boolean status, int price, int quantity, String descreption, String coverPath, Category[] categories) { + this( title, author, publicationYear, status, price, quantity, descreption, coverPath); this.categories = new ArrayList(Arrays.asList(categories)); } + public int getIdCounter() { + return idCounter; + } + public void setIdCounter(int idCounter) { + this.idCounter = idCounter; + } public int getId() { return id; } diff --git a/src/main/java/com/asu/librarysystem/BookController.java b/src/main/java/com/asu/librarysystem/BookController.java index b046139..df8a137 100644 --- a/src/main/java/com/asu/librarysystem/BookController.java +++ b/src/main/java/com/asu/librarysystem/BookController.java @@ -22,6 +22,7 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.stage.Stage; @@ -84,7 +85,7 @@ public void setScene(Book book) throws IOException { setProperties(book.getTitle(), book.getAuthor(), Integer.toString(book.getPublicationYear()) , book.getDescription(), book.getPrice(), book.getQuantity()); - Library.getReviewHandler().addReview(1, book.getId(), 3, "I don't love this book"); + Library.getReviewHandler().addReview(2, book.getId(), 1, "I don't love this book"); ArrayList ratings = Library.getReviewHandler().getBookRatings(book.getId()); setRatings(ratings); @@ -270,7 +271,7 @@ private void showRecommendations() throws IOException { for (Book book : availableBooks){ if (counter == 6) break; - if (findingCommonCategories(book)){ + if (findingCommonCategories(book) && book.getId() != currentBook.getId() && book.isAvailable()){ FXMLLoader fxmlLoader=new FXMLLoader(); fxmlLoader.setLocation(getClass().getResource("Book-View-Card.fxml")); @@ -333,6 +334,9 @@ public void submitReview(ActionEvent event) throws FileNotFoundException { Account activeUser = Library.getActiveAccount(); Library.getReviewHandler().addReview(activeUser.getId(), currentBook.getId(), ratingOptions.getValue(), reviewTextArea.getText()); + reviewTextArea.setText(""); + warningMessage.setFill(Color.GREEN); + warningMessage.setText("Review added successfully"); System.out.println("review added"); showComments(Library.getReviewHandler().getBookReviews(currentBook.getId())); @@ -384,13 +388,26 @@ private void showComments(ArrayList comments) throws FileNotFoundExcepti Label username = new Label(); - username.setText(Integer.toString(comment.getReviewerId())); + + +// ArrayList borrowers = Library.getBorrowers(); +// ArrayList customers = Library.getCustomers(); +// if(Library.searchCustomerByID(comment.getReviewerId())==null){ +// name= Library.searchBorrwerByID(comment.getReviewerId()).getUserName(); +// } +// else { +// name= Library.searchCustomerByID(comment.getReviewerId()).getUserName(); +// } + + String name=Library.searchAccountById(comment.getReviewerId()).getUserName(); + + username.setText(name);//String.valueOf(comment.getReviewerId()) username.setStyle("-fx-font-weight: 200;"); username.setStyle("-fx-font-size: 20px;"); ImageView rate = new ImageView(); - rate.setFitWidth(228); + rate.setFitWidth(190);//228 rate.setFitHeight(50); if (comment.getRating() == 1){ rate.setImage(oneStar); diff --git a/src/main/java/com/asu/librarysystem/Borrower.java b/src/main/java/com/asu/librarysystem/Borrower.java index e5fac78..fc125d8 100644 --- a/src/main/java/com/asu/librarysystem/Borrower.java +++ b/src/main/java/com/asu/librarysystem/Borrower.java @@ -1,5 +1,6 @@ package com.asu.librarysystem; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Date; @@ -20,6 +21,12 @@ public Borrower(String borrowerName, String password, String PhoneNumber) { assignBefore = false; } + public Borrower(int id,String borrowerName, String password, String PhoneNumber) { + super(id,borrowerName, password, PhoneNumber); + borrowerTransactions = new ArrayList<>(); + assignBefore = false; + } + public void addReservation(Book book) { reservedBooks.add(book); @@ -43,6 +50,12 @@ public void addTransaction(Book book) { getReservedBooks().remove(book); } } + public void addTransaction(int bookId, int borrowerId, LocalDate borrowDate, LocalDate returnDate) { + borrowerTransactions.add(new Transaction(bookId,borrowerId, getId(), borrowDate, returnDate)); + } + public void addTransaction(Transaction transaction){ + addTransaction(transaction.getBookId(),transaction.getBorrowerId(),transaction.getBorrowDate(),transaction.getReturnDate()); + } public boolean deleteTransaction(int transactionId) { try { diff --git a/src/main/java/com/asu/librarysystem/Customer.java b/src/main/java/com/asu/librarysystem/Customer.java index f6a1c14..e2e4fd7 100644 --- a/src/main/java/com/asu/librarysystem/Customer.java +++ b/src/main/java/com/asu/librarysystem/Customer.java @@ -13,6 +13,11 @@ public class Customer extends Account { orders = new ArrayList(); assignBefore = false; } + Customer(int id ,String userName, String password, String phoneNumber) { + super(id,userName, password, phoneNumber); + orders = new ArrayList(); + assignBefore = false; + } private int findOrder(int orderId) { for (int i = 0; i < orders.size(); i++) { @@ -28,6 +33,10 @@ public void addOrder(int bookId, int quantity) { orders.add(new Order(bookId, quantity)); } + public void addOrder(Order order){ + addOrder(order.getBookId(),order.getQuantity()); + } + public void deleteOrder(int orderId) { int orderIndex = findOrder(orderId); diff --git a/src/main/java/com/asu/librarysystem/DiscountHandler.java b/src/main/java/com/asu/librarysystem/DiscountHandler.java index 77f6703..a1af8a6 100644 --- a/src/main/java/com/asu/librarysystem/DiscountHandler.java +++ b/src/main/java/com/asu/librarysystem/DiscountHandler.java @@ -41,4 +41,8 @@ private int findDiscount(String code) { } return -1; } + public void addDiscount(Discount discount){ + addDiscount(discount.getCode(),discount.getDiscount()); + } + } diff --git a/src/main/java/com/asu/librarysystem/Library.java b/src/main/java/com/asu/librarysystem/Library.java index c7b9174..bd723c9 100644 --- a/src/main/java/com/asu/librarysystem/Library.java +++ b/src/main/java/com/asu/librarysystem/Library.java @@ -1,6 +1,7 @@ package com.asu.librarysystem; import java.io.*; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Scanner; import java.util.Stack; @@ -10,7 +11,7 @@ public class Library { private static ArrayList customers = new ArrayList(); private static ArrayList borrowers = new ArrayList(); private static Account activeAccount; - private static Admin admin = new Admin("Ahmad" , "1234" ,"01030243591") ; + private static Admin admin = new Admin("admin" , "admin" ,"1111") ; private static ReviewHandler reviewHandler = new ReviewHandler(); private static DiscountHandler discountHandler = new DiscountHandler(); private static Stack previousBooks = new Stack(); @@ -394,156 +395,259 @@ public static ArrayList getBorrowers() { return borrowers; } + public static Account searchAccountById(int id) { + for (Customer b : customers) { + if (b.getId() == id) { + return b; + } + } + for (Borrower m : borrowers) { + if (m.getId() == id) { + return m; + } + } + return null; + + } + + public static void writeLibrary () { + try { + FileOutputStream write1 = new FileOutputStream("data/datafiles/books_data.txt"); + for (Book obj : books) { + write1.write((obj.getIdCounter() + ",,," + obj.getId() + ",,," + obj.getTitle() + ",,," + obj.getAuthor() + ",,," + obj.getPublicationYear() + ",,," + obj.isStatus() + ",,," + obj.getPrice() + ",,," + obj.getQuantity() + ",,," + obj.getDescription() + ",,," + obj.getCoverPath() + "\n").getBytes()); + ArrayList categories = obj.getCategories(); + for (Category c : categories) { + write1.write((c.name() + ",,,").getBytes()); + } + write1.write("\n".getBytes()); + } + write1.close(); + } catch (FileNotFoundException e) { + System.out.println("can't write"); + } catch (IOException e) { + System.out.println("can't write"); + } + + try { + FileOutputStream write2 = new FileOutputStream("data/datafiles/customers_data.txt"); + for (Customer obj : customers) { + write2.write((obj.getIdCounter() + ",,," + obj.getId() + ",,," + obj.getUserName() + ",,," + obj.getPassword() + ",,," + obj.getPhoneNumber() + "\n").getBytes()); + } + write2.close(); + } catch (FileNotFoundException e) { + System.out.println("can't write"); + } catch (IOException e) { + System.out.println("can't write"); + } + try { + FileOutputStream write3 = new FileOutputStream("data/datafiles/borrowers_data.txt"); + for (Borrower obj : borrowers) { + write3.write((obj.getIdCounter() + ",,," + obj.getId() + ",,," + obj.getUserName() + ",,," + obj.getPassword() + ",,," + obj.getPhoneNumber() + "\n").getBytes()); + } + write3.close(); + } catch (FileNotFoundException e) { + System.out.println("can't write"); + } catch (IOException e) { + System.out.println("can't write"); + } + + for (Borrower borrower : borrowers) { + ArrayList transactions = borrower.getBorrowerTransactions(); + try { + FileOutputStream write = new FileOutputStream("data/datafiles/transaction_data_" + borrower.getUserName() + ".txt"); + for (Transaction obj : transactions) { + write.write((obj.getTransactionCount() + ",,," + obj.getTransactionId() + ",,," + obj.getBookId() + ",,," + obj.getBorrowerId() + ",,," + obj.getBorrowDate() + ",,," + obj.getReturnDate() + "\n").getBytes()); + } + write.close(); + } catch (FileNotFoundException e) { + System.out.println("can't write"); + } catch (IOException e) { + System.out.println("can't write"); + } + + } + + for (Customer customer : customers) { + ArrayList orders = customer.getOrders(); + try { + FileOutputStream write = new FileOutputStream("data/datafiles/order_data_" + customer.getUserName() + ".txt"); + for (Order obj : orders) { + write.write((obj.getIdCounter() + ",,," + obj.getId() + ",,," + obj.getBookId() + ",,," + obj.getQuantity() + "\n").getBytes()); + } + write.close(); + } catch (FileNotFoundException e) { + System.out.println("can't write"); + } catch (IOException e) { + System.out.println("can't write"); + } + + } + try { + FileOutputStream write1 = new FileOutputStream("data/datafiles/reviews_data.txt"); + ArrayList reviews = reviewHandler.getReviews(); + for (Review obj : reviews) { + write1.write((obj.getIdCounter() + ",,," + obj.getId() + ",,," + obj.getReviewerId() + ",,," + obj.getBookId() + ",,," + obj.getRating() + ",,," + obj.getText() + "\n").getBytes()); + } + write1.close(); + } catch (FileNotFoundException e) { + System.out.println("can't write"); + } catch (IOException e) { + System.out.println("can't write"); + } + try { + FileOutputStream write1 = new FileOutputStream("data/datafiles/discount_data.txt"); + ArrayList discounts = discountHandler.getDiscounts(); + for (Discount obj : discounts) { + write1.write((obj.getCode() + ",,," + obj.getDiscount() + "\n").getBytes()); + } + write1.close(); + } catch (FileNotFoundException e) { + System.out.println("can't write"); + } catch (IOException e) { + System.out.println("can't write"); + } + } + + public static void readLibrary () { + Scanner scanner1 = null; + try { + + scanner1 = new Scanner(new FileInputStream("data/datafiles/books_data.txt")); + } catch (FileNotFoundException e) { + System.out.println("can't read"); + } + + while (scanner1.hasNextLine()) { + String line1 = scanner1.nextLine(); + String[] parts1 = line1.split(",,,"); + String line2 = scanner1.nextLine(); + String[] parts2 = line2.split(",,,"); + ArrayList categories = new ArrayList(); + for (String s : parts2) { + switch (s) { + case "HORROR": + categories.add(Category.HORROR); + break; + case "DRAMA": + categories.add(Category.DRAMA); + break; + case "NOVEL": + categories.add(Category.NOVEL); + break; + case "SELFDEVELOPMENT": + categories.add(Category.SELFDEVELOPMENT); + break; + case "ADVENTURE": + categories.add(Category.ADVENTURE); + break; + default: + break; + } + } + Book book = new Book(Integer.valueOf(parts1[1]), parts1[2], parts1[3], Integer.valueOf(parts1[4]), Boolean.valueOf(parts1[5]), Integer.valueOf(parts1[6]), Integer.valueOf(parts1[7]), parts1[8], parts1[9], categories); + book.setIdCounter(Integer.valueOf(parts1[0])); + addBook(book); + } + scanner1.close(); + + Scanner scanner2 = null; + try { + scanner2 = new Scanner(new FileInputStream("data/datafiles/customers_data.txt")); + } catch (FileNotFoundException e) { + System.out.println("can't read"); + } + + while (scanner2.hasNextLine()) { + String line2 = scanner2.nextLine(); + String[] parts2 = line2.split(",,,"); + Customer customer = new Customer(Integer.valueOf(parts2[1]), parts2[2], parts2[3], parts2[4]); + customer.setIdCounter(Integer.valueOf(parts2[0])); + addCustomer(customer); + } + scanner2.close(); + + Scanner scanner3 = null; + try { + scanner3 = new Scanner(new FileInputStream("data/datafiles/borrowers_data.txt")); + } catch (FileNotFoundException e) { + System.out.println("can't read"); + } + + while (scanner3.hasNextLine()) { + String line3 = scanner3.nextLine(); + String[] parts3 = line3.split(",,,"); + Borrower borrower = new Borrower(Integer.valueOf(parts3[1]), parts3[2], parts3[3], parts3[4]); + borrower.setIdCounter(Integer.valueOf(parts3[0])); + addBorrower(borrower); + } + scanner3.close(); + + for (Borrower borrower : borrowers) { + Scanner scanner = null; + try { + scanner = new Scanner(new FileInputStream("data/datafiles/transaction_data_" + borrower.getUserName() + ".txt")); + } catch (FileNotFoundException e) { + System.out.println("can't read"); + } + + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + String[] parts = line.split(",,,"); + Transaction transaction = new Transaction(Integer.valueOf(parts[1]), Integer.valueOf(parts[2]), Integer.valueOf(parts[3]), LocalDate.parse(parts[4]), LocalDate.parse(parts[5])); + transaction.setTransactionCount(Integer.valueOf(parts[0])); + borrower.addTransaction(transaction); + } + scanner.close(); + } + + for (Customer customer : customers) { + Scanner scanner = null; + try { + scanner = new Scanner(new FileInputStream("data/datafiles/order_data_" + customer.getUserName() + ".txt")); + } catch (FileNotFoundException e) { + System.out.println("can't read"); + } + + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + String[] parts = line.split(",,,"); + Order order = new Order(Integer.valueOf(parts[1]), Integer.valueOf(parts[2]), Integer.valueOf(parts[3])); + customer.setIdCounter(Integer.valueOf(parts[0])); + customer.addOrder(order); + } + scanner.close(); + } + + Scanner scanner4 = null; + try { + scanner4 = new Scanner(new FileInputStream("data/datafiles/reviews_data.txt")); + } catch (FileNotFoundException e) { + System.out.println("can't read"); + } + + while (scanner4.hasNextLine()) { + String line1 = scanner4.nextLine(); + String[] parts1 = line1.split(",,,"); + Review review = new Review(Integer.valueOf(parts1[1]), Integer.valueOf(parts1[2]), Integer.valueOf(parts1[3]), Integer.valueOf(parts1[4]), parts1[5]); + review.setIdCounter(Integer.valueOf(parts1[0])); + reviewHandler.addReview(review); + } + + scanner4.close(); + Scanner scanner5 = null; + try { + scanner5 = new Scanner(new FileInputStream("data/datafiles/discount_data.txt")); + } catch (FileNotFoundException e) { + System.out.println("can't read"); + } + + while (scanner5.hasNextLine()) { + String line1 = scanner5.nextLine(); + String[] parts1 = line1.split(",,,"); + Discount discount = new Discount(parts1[0], Double.valueOf(parts1[1])); + discountHandler.addDiscount(discount); + } + scanner5.close(); + } -// public static void writeLibrary() { -// try { -// FileOutputStream write1=new FileOutputStream("books_data.txt"); -// for (Book obj : books) { -// write1.write((obj.getId()+","+obj.getTitle()+","+obj.getAuthor()+","+obj.getPublicationYear()+","+obj.isStatus()+","+obj.getPrice()+","+obj.getCoverPath()+"\n").getBytes()); -// } -// write1.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// -// try { -// FileOutputStream write2=new FileOutputStream("customers_data.txt"); -// for (Customer obj : customers) { -// write2.write((obj.getId()+","+obj.getUserName()+","+obj.getPassword()+","+obj.getPhoneNumber()+"\n").getBytes()); -// } -// write2.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// try { -// FileOutputStream write3=new FileOutputStream("borrowers_data.txt"); -// for (Borrower obj : borrowers) { -// write3.write((obj.getId()+","+obj.getUserName()+","+obj.getPassword()+","+obj.getPhoneNumber()+"\n").getBytes()); -// } -// write3.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// -// for(Borrower borrower : borrowers){ -// ArrayList transactions =borrower.copyElementOfArrayList(); -// try { -// FileOutputStream write=new FileOutputStream("transaction_data_"+borrower.getUserName()+".txt"); -// for (Transaction obj : transactions ) { -// String bookName=searchBookById(obj.getBookId()).getTitle(); -// write.write((obj.getTransactionId()+","+bookName+","+obj.getBorrowerId()+","+obj.getBorrowDate()+","+obj.getReturnDate()+"\n").getBytes()); -// } -// write.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// -// } -// -// for(Customer customer : customers){ -// ArrayList orders =customer.copyElementOfArrayList(); -// try { -// FileOutputStream write=new FileOutputStream("order_data_"+customer.getUserName()+".txt"); -// for (Order obj : orders ) { -// String bookName=searchBookById(obj.getBookId()).getTitle(); -// write.write((obj.getId()+","+bookName+","+obj.getQuantity()+"\n").getBytes()); -// } -// write.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// -// } -// } - -// public static void readLibrary() { -// Scanner scanner1 = null; -// try { -// scanner1 = new Scanner(new FileInputStream("books_data.txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner1.hasNextLine()) { -// String line1 = scanner1.nextLine(); -// String[] parts1 = line1.split(","); -//// Book book=new Book(parts1[1],parts1[2],Integer.valueOf(parts1[3]),Boolean.valueOf(parts1[4]),Integer.valueOf(parts1[5]),Integer.valueOf(parts1[6]),parts1[7]); -// addBook(book); -// } -// scanner1.close(); -// -// Scanner scanner2 = null; -// try { -// scanner2 = new Scanner(new FileInputStream("customers_data.txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner2.hasNextLine()) { -// String line2 = scanner2.nextLine(); -// String[] parts2 = line2.split(","); -// Customer customer=new Customer(parts2[1],parts2[2],parts2[3]); -// addCustomer(customer); -// } -// scanner2.close(); -// -// Scanner scanner3 = null; -// try { -// scanner3 = new Scanner(new FileInputStream("borrowers_data.txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner3.hasNextLine()) { -// String line3 = scanner3.nextLine(); -// String[] parts3 = line3.split(","); -// Borrower borrower = new Borrower(parts3[1],parts3[2],parts3[3]); -// addBorrower(borrower); -// } -// scanner3.close(); -// -// for(Borrower borrower : borrowers) { -// Scanner scanner = null; -// try { -// scanner = new Scanner(new FileInputStream("transaction_data_"+borrower.getUserName()+".txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner.hasNextLine()) { -// String line = scanner.nextLine(); -// String[] parts = line.split(","); -// Transaction transaction = new Transaction(searchBookByTitle(parts[1]).getId(), borrower.getId(), Integer.valueOf(parts[3]), Integer.valueOf(parts[4])); -// borrower.addTransaction(searchBookById(transaction.getBookId()), transaction.getBorrowDate(),transaction.getReturnDate()); -// } -// scanner.close(); -// } -// -// for(Customer customer : customers) { -// Scanner scanner = null; -// try { -// scanner = new Scanner(new FileInputStream("order_data_"+customer.getUserName()+".txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner.hasNextLine()) { -// String line = scanner.nextLine(); -// String[] parts = line.split(","); -// Order order = new Order(searchBookByTitle(parts[1]).getId(),Integer.valueOf(parts[2])); -// customer.addOrder(order.getBookId(),order.getQuantity()); -// } -// scanner.close(); -// } -// } } diff --git a/src/main/java/com/asu/librarysystem/MainApplication.java b/src/main/java/com/asu/librarysystem/MainApplication.java index 103f464..ba8fe07 100644 --- a/src/main/java/com/asu/librarysystem/MainApplication.java +++ b/src/main/java/com/asu/librarysystem/MainApplication.java @@ -67,43 +67,46 @@ public static void main(String[] args) { , """", new Category[]{Category.HORROR, Category.DRAMA});*/ //Book book100 = new Book("Harry Potter and the Prisoner of Azkaban","J. K. Rowling",2023,true,200,4,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.HORROR}); +// +// Book book1 = new Book("Harry Potter and the Prisoner of Azkaban","J. K. Rowling",2023,true,200,4,"Harry Potter and the Prisoner of Azkaban is a fantasy novel written by British author J. K. Rowling and is the third in the Harry Potter series. The book follows Harry Potter, a young wizard, in his third year at Hogwarts School of Witchcraft and Wizardry. Along with friends Ronald Weasley and Hermione Granger, Harry investigates Sirius Black, an escaped prisoner from Azkaban, the wizard prison, believed to be one of Lord Voldemort's old allies.", "src/main/resources/image/Harry_Potter_and_the_Prisoner_of_Azkaban.jpg", new Category[]{Category.HORROR}); +// Book book2 = new Book("Harry Potter and the Chamber of Secrets","J. K. Rowling",2020,true,200,3,"Harry Potter and the Chamber of Secrets is a fantasy novel written by British author J. K. Rowling and the second novel in the Harry Potter series. The plot follows Harry's second year at Hogwarts School of Witchcraft and Wizardry, during which a series of messages on the walls of the school's corridors warn that the \"Chamber of Secrets\" has been opened and that the \"heir of Slytherin\" would kill all pupils who do not come from all-magical families. These threats are found after attacks that leave residents of the school petrified. Throughout the year, Harry and his friends Ron and Hermione investigate the attacks.", "src/main/resources/image/Harry_Potter_and_the_Chamber_of_Secrets.jpg", new Category[]{Category.ADVENTURE}); +// Book book3 = new Book("The Alchemist ","Paulo Coelho ",2021,true,200,2,"The Alchemist (Portuguese: O Alquimista) is a novel by Brazilian author Paulo Coelho which was first published in 1988. Originally written in Portuguese, it became a widely translated international bestseller.[1][2] The story follows the shepherd boy Santiago in his journey across northern Africa to the pyramids of Egypt after he dreams of finding a treasure there.", "src/main/resources/image/TheAlchemist.jpg", new Category[]{Category.ADVENTURE}); +// Book book4 = new Book("A Tale of Two Cities","Charles Dickens",2023,true,200,4,"A Tale of Two Cities is a historical novel published in 1859 by Charles Dickens, set in London and Paris before and during the French Revolution. The novel tells the story of the French Doctor Manette, his 18-year-long imprisonment in the Bastille in Paris, and his release to live in London with his daughter Lucie whom he had never met. The story is set against the conditions that led up to the French Revolution and the Reign of Terror.", "src/main/resources/image/Tales_serial.jpg", new Category[]{Category.ADVENTURE}); +// Book book5 = new Book("The Little Prince ","Antoine de Saint-Exupéry",2020,true,200,3,"The Little Prince (French: Le Petit Prince, pronounced [lə p(ə)ti pʁɛ̃s]) is a novella written and illustrated by French aristocrat, writer, and military pilot Antoine de Saint-Exupéry. It was first published in English and French in the United States by Reynal & Hitchcock in April 1943 and was published posthumously in France following liberation; Saint-Exupéry's works had been banned by the Vichy Regime. The story follows a young prince who visits various planets, including Earth, and addresses themes of loneliness, friendship, love, and loss. Despite its style as a children's book, The Little Prince makes observations about life, adults, and human nature.", "src/main/resources/image/Littleprince.jpeg", new Category[]{Category.ADVENTURE}); +// Book book6 = new Book("Harry Potter and the Philosopher's Stone","J. K. Rowling",2021,true,200,2,"Harry Potter and the Philosopher's Stone is a fantasy novel written by British author J. K. Rowling. The first novel in the Harry Potter series and Rowling's debut novel, it follows Harry Potter, a young wizard who discovers his magical heritage on his eleventh birthday, when he receives a letter of acceptance to Hogwarts School of Witchcraft and Wizardry. Harry makes close friends and a few enemies during his first year at the school and with the help of his friends, Ron Weasley and Hermione Granger, he faces an attempted comeback by the dark wizard Lord Voldemort, who killed Harry's parents, but failed to kill Harry when he was just 15 months old.", "src/main/resources/image/Harry_Potter_and_the_Philosopher's_Stone_Book_Cover.jpg", new Category[]{Category.ADVENTURE}); +// Book book7 = new Book("And Then There Were None","Agatha Christie",2023,true,200,4,"And Then There Were None is a mystery novel by the English writer Agatha Christie, who described it as the most difficult of her books to write.[2] It was first published in the United Kingdom by the Collins Crime Club on 6 November 1939, as Ten Little Niggers,[3] after an 1869 minstrel song that serves as a major plot element.[4][5] The US edition was released in January 1940 with the title And Then There Were None, taken from the last five words of the song.[6] Successive American reprints and adaptations use that title, though American Pocket Books paperbacks used the title Ten Little Indians between 1964 and 1986. UK editions continued to use the original title until 1985.[7]", "src/main/resources/image/And_Then_There_Were_None_First_Edition_Cover_1939.jpg", new Category[]{Category.ADVENTURE}); +// Book book8 = new Book("The Hobbit","J. R. R. Tolkien",2020,true,200,3,"The Hobbit, or There and Back Again is a children's fantasy novel by English author J. R. R. Tolkien. It was published in 1937 to wide critical acclaim, being nominated for the Carnegie Medal and awarded a prize from the New York Herald Tribune for best juvenile fiction. The book is recognized as a classic in children's literature and is one of the best-selling books of all time, with over 100 million copies sold.", "src/main/resources/image/TheHobbit_FirstEdition.jpg", new Category[]{Category.ADVENTURE, Category.HORROR}); +// Book book9 = new Book("She: A History of Adventure","H. Rider Haggard",2021,true,200,2,"She, subtitled A History of Adventure, is a novel by the English writer H. Rider Haggard, published in book form in 1887 following serialisation in The Graphic magazine between October 1886 and January 1887. She was extraordinarily popular upon its release and has never been out of print.", "src/main/resources/image/330px-SHE,_A_History_of_Adventure_(1st_Edition_Cover),_by_H._Rider_Haggard.jpg", new Category[]{Category.ADVENTURE}); +// Book book10 = new Book("The Da Vinci Code","Dan Brown",2021,true,200,2,"The Da Vinci Code is a 2003 mystery thriller novel by Dan Brown. It is Brown's second novel to include the character Robert Langdon: the first was his 2000 novel Angels & Demons. The Da Vinci Code follows symbologist Robert Langdon and cryptologist Sophie Neveu after a murder in the Louvre Museum in Paris causes them to become involved in a battle between the Priory of Sion and Opus Dei over the possibility of Jesus Christ and Mary Magdalene having had a child together.", "src/main/resources/image/DaVinciCode.jpg", new Category[]{Category.ADVENTURE}); +// Library.addBook(book1); +// Library.addBook(book2); +// Library. addBook(book3); +// Library.addBook(book4); +// Library.addBook(book5); +// Library.addBook(book6); +// Library.addBook(book7); +// Library.addBook(book8); +// Library.addBook(book9); +// Library.addBook(book10); +// Customer customer=new Customer("user1","user1","111"); +// Library.addCustomer(customer); +// Borrower borrower = new Borrower("user2","user2","111"); +// Library.addBorrower(borrower); +// //Library.logInByUserName("ib","123"); +// +// customer.addOrder(book1.getId(),2); +// customer.addOrder(book2.getId(),2); +// customer.addOrder(book3.getId(),1); +// customer.addOrder(book5.getId(),2); +// customer.addOrder(book7.getId(),2); +// +// borrower.addTransaction(book3); +// borrower.addTransaction(book5); +// borrower.addTransaction(book9); - Book book1 = new Book("Harry Potter and the Prisoner of Azkaban","J. K. Rowling",2023,true,200,4,"Harry Potter and the Prisoner of Azkaban is a fantasy novel written by British author J. K. Rowling and is the third in the Harry Potter series. The book follows Harry Potter, a young wizard, in his third year at Hogwarts School of Witchcraft and Wizardry. Along with friends Ronald Weasley and Hermione Granger, Harry investigates Sirius Black, an escaped prisoner from Azkaban, the wizard prison, believed to be one of Lord Voldemort's old allies.", "src/main/resources/image/Harry_Potter_and_the_Prisoner_of_Azkaban.jpg", new Category[]{Category.HORROR}); - Book book2 = new Book("Harry Potter and the Chamber of Secrets","J. K. Rowling",2020,true,200,3,"Harry Potter and the Chamber of Secrets is a fantasy novel written by British author J. K. Rowling and the second novel in the Harry Potter series. The plot follows Harry's second year at Hogwarts School of Witchcraft and Wizardry, during which a series of messages on the walls of the school's corridors warn that the \"Chamber of Secrets\" has been opened and that the \"heir of Slytherin\" would kill all pupils who do not come from all-magical families. These threats are found after attacks that leave residents of the school petrified. Throughout the year, Harry and his friends Ron and Hermione investigate the attacks.", "src/main/resources/image/Harry_Potter_and_the_Chamber_of_Secrets.jpg", new Category[]{Category.ADVENTURE}); - Book book3 = new Book("The Alchemist ","Paulo Coelho ",2021,true,200,2,"The Alchemist (Portuguese: O Alquimista) is a novel by Brazilian author Paulo Coelho which was first published in 1988. Originally written in Portuguese, it became a widely translated international bestseller.[1][2] The story follows the shepherd boy Santiago in his journey across northern Africa to the pyramids of Egypt after he dreams of finding a treasure there.", "src/main/resources/image/TheAlchemist.jpg", new Category[]{Category.ADVENTURE}); - Book book4 = new Book("A Tale of Two Cities","Charles Dickens",2023,true,200,4,"A Tale of Two Cities is a historical novel published in 1859 by Charles Dickens, set in London and Paris before and during the French Revolution. The novel tells the story of the French Doctor Manette, his 18-year-long imprisonment in the Bastille in Paris, and his release to live in London with his daughter Lucie whom he had never met. The story is set against the conditions that led up to the French Revolution and the Reign of Terror.", "src/main/resources/image/Tales_serial.jpg", new Category[]{Category.ADVENTURE}); - Book book5 = new Book("The Little Prince ","Antoine de Saint-Exupéry",2020,true,200,3,"The Little Prince (French: Le Petit Prince, pronounced [lə p(ə)ti pʁɛ̃s]) is a novella written and illustrated by French aristocrat, writer, and military pilot Antoine de Saint-Exupéry. It was first published in English and French in the United States by Reynal & Hitchcock in April 1943 and was published posthumously in France following liberation; Saint-Exupéry's works had been banned by the Vichy Regime. The story follows a young prince who visits various planets, including Earth, and addresses themes of loneliness, friendship, love, and loss. Despite its style as a children's book, The Little Prince makes observations about life, adults, and human nature.", "src/main/resources/image/Littleprince.jpeg", new Category[]{Category.ADVENTURE}); - Book book6 = new Book("Harry Potter and the Philosopher's Stone","J. K. Rowling",2021,true,200,2,"Harry Potter and the Philosopher's Stone is a fantasy novel written by British author J. K. Rowling. The first novel in the Harry Potter series and Rowling's debut novel, it follows Harry Potter, a young wizard who discovers his magical heritage on his eleventh birthday, when he receives a letter of acceptance to Hogwarts School of Witchcraft and Wizardry. Harry makes close friends and a few enemies during his first year at the school and with the help of his friends, Ron Weasley and Hermione Granger, he faces an attempted comeback by the dark wizard Lord Voldemort, who killed Harry's parents, but failed to kill Harry when he was just 15 months old.", "src/main/resources/image/Harry_Potter_and_the_Philosopher's_Stone_Book_Cover.jpg", new Category[]{Category.ADVENTURE}); - Book book7 = new Book("And Then There Were None","Agatha Christie",2023,true,200,4,"And Then There Were None is a mystery novel by the English writer Agatha Christie, who described it as the most difficult of her books to write.[2] It was first published in the United Kingdom by the Collins Crime Club on 6 November 1939, as Ten Little Niggers,[3] after an 1869 minstrel song that serves as a major plot element.[4][5] The US edition was released in January 1940 with the title And Then There Were None, taken from the last five words of the song.[6] Successive American reprints and adaptations use that title, though American Pocket Books paperbacks used the title Ten Little Indians between 1964 and 1986. UK editions continued to use the original title until 1985.[7]", "src/main/resources/image/And_Then_There_Were_None_First_Edition_Cover_1939.jpg", new Category[]{Category.ADVENTURE}); - Book book8 = new Book("The Hobbit","J. R. R. Tolkien",2020,true,200,3,"The Hobbit, or There and Back Again is a children's fantasy novel by English author J. R. R. Tolkien. It was published in 1937 to wide critical acclaim, being nominated for the Carnegie Medal and awarded a prize from the New York Herald Tribune for best juvenile fiction. The book is recognized as a classic in children's literature and is one of the best-selling books of all time, with over 100 million copies sold.", "src/main/resources/image/TheHobbit_FirstEdition.jpg", new Category[]{Category.ADVENTURE, Category.HORROR}); - Book book9 = new Book("She: A History of Adventure","H. Rider Haggard",2021,true,200,2,"She, subtitled A History of Adventure, is a novel by the English writer H. Rider Haggard, published in book form in 1887 following serialisation in The Graphic magazine between October 1886 and January 1887. She was extraordinarily popular upon its release and has never been out of print.", "src/main/resources/image/330px-SHE,_A_History_of_Adventure_(1st_Edition_Cover),_by_H._Rider_Haggard.jpg", new Category[]{Category.ADVENTURE}); - Book book10 = new Book("The Da Vinci Code","Dan Brown",2021,true,200,2,"The Da Vinci Code is a 2003 mystery thriller novel by Dan Brown. It is Brown's second novel to include the character Robert Langdon: the first was his 2000 novel Angels & Demons. The Da Vinci Code follows symbologist Robert Langdon and cryptologist Sophie Neveu after a murder in the Louvre Museum in Paris causes them to become involved in a battle between the Priory of Sion and Opus Dei over the possibility of Jesus Christ and Mary Magdalene having had a child together.", "src/main/resources/image/DaVinciCode.jpg", new Category[]{Category.ADVENTURE}); - Library.addBook(book1); - Library.addBook(book2); - Library. addBook(book3); - Library.addBook(book4); - Library.addBook(book5); - Library.addBook(book6); - Library.addBook(book7); - Library.addBook(book8); - Library.addBook(book9); - Library.addBook(book10); - Customer customer=new Customer("ib","123","111"); - Library.addCustomer(customer); - Borrower borrower = new Borrower("Ibrahem","111","111"); - Library.addBorrower(borrower); - //Library.logInByUserName("ib","123"); - - customer.addOrder(book1.getId(),2); - customer.addOrder(book2.getId(),2); - customer.addOrder(book3.getId(),1); - customer.addOrder(book5.getId(),2); - customer.addOrder(book7.getId(),2); - - borrower.addTransaction(book3); - borrower.addTransaction(book5); - borrower.addTransaction(book9); + // Library.writeLibrary(); + Library.readLibrary(); /* Login Borrower B = new Borrower("Hossam", "123456", "123456"); @@ -127,6 +130,8 @@ public static void main(String[] args) { launch(); + Library.writeLibrary(); + } diff --git a/src/main/java/com/asu/librarysystem/Order.java b/src/main/java/com/asu/librarysystem/Order.java index b6a0d9a..898eafd 100644 --- a/src/main/java/com/asu/librarysystem/Order.java +++ b/src/main/java/com/asu/librarysystem/Order.java @@ -14,6 +14,19 @@ public Order(int bookId, int quantity) { this.quantity = quantity; this.discountCode = ""; } + public Order(int id,int bookId, int quantity) { + this.id = id; + this.bookId = bookId; + this.quantity = quantity; + this.discountCode = ""; + } + + public int getIdCounter(){ + return idCounter; + } + public void setIdCounter(int idCounter){ + this.idCounter= idCounter; + } public int getId() { return id; diff --git a/src/main/java/com/asu/librarysystem/Review.java b/src/main/java/com/asu/librarysystem/Review.java index cbade5b..b473645 100644 --- a/src/main/java/com/asu/librarysystem/Review.java +++ b/src/main/java/com/asu/librarysystem/Review.java @@ -15,13 +15,24 @@ public Review(int reviewerId, int bookId, int rating, String text) { setRating(rating); this.text = text; } + public Review(int id, int reviewerId, int bookId, int rating, String text) { + this.id = id; + this.reviewerId = reviewerId; + this.bookId = bookId; + setRating(rating); + this.text = text; + } public Review(Review review) { - this.id = review.id; - this.reviewerId = review.reviewerId; - this.bookId = review.bookId; - this.rating = review.rating; - this.text = review.text; + this(review.getId(), review.getReviewerId(), review.getBookId(),review.getRating(),review.getText()); } + + public int getIdCounter(){ + return idCounter; + } + public void setIdCounter(int idCounter){ + this.idCounter=idCounter; + } + public void setRating(int rating) { if (rating > 5) this.rating = 5; diff --git a/src/main/java/com/asu/librarysystem/ReviewHandler.java b/src/main/java/com/asu/librarysystem/ReviewHandler.java index ea04711..ce70eb0 100644 --- a/src/main/java/com/asu/librarysystem/ReviewHandler.java +++ b/src/main/java/com/asu/librarysystem/ReviewHandler.java @@ -100,4 +100,26 @@ private Review findReview(int reviewerId, int bookId) { else return reviews.get(index); } + public void addReview(int id, int reviewerId, int bookId, int rating, String text) { + Review review = findReview(reviewerId, bookId); + if (review.getReviewerId() != -1) { + updateReview(reviewerId, bookId, rating, text); + return; + } + review = new Review(id,reviewerId, bookId, rating, text); + + reviews.add(review); + if (!bookRatings.containsKey(bookId)) { + bookRatings.put(bookId, new ArrayList()); + for (int i = 0; i < 6; i++) + bookRatings.get(bookId).add(0); + } + addBookRating(bookId, review.getRating()); + } + public void addReview(Review review) { + addReview(review.getId(),review.getReviewerId(),review.getBookId(),review.getRating(),review.getText()); + } + public ArrayList getReviews(){ + return reviews; + } } diff --git a/src/main/java/com/asu/librarysystem/Transaction.java b/src/main/java/com/asu/librarysystem/Transaction.java index 994d346..9e9e091 100644 --- a/src/main/java/com/asu/librarysystem/Transaction.java +++ b/src/main/java/com/asu/librarysystem/Transaction.java @@ -24,6 +24,28 @@ public Transaction(Book book, int borrowerId) this.bookName = Library.searchBookById(bookId).getTitle(); this.transactionId = ++transactionCount; } + public Transaction(int id,int bookId,int borrowerId, LocalDate borrowDate,LocalDate returnDate) + { + this.bookId=bookId; + this.borrowerId=borrowerId; + this.borrowDate=borrowDate; + this.returnDate=returnDate; + this.bookName = bookName; + this.transactionId = id; + } + public Transaction(int bookId,int borrowerId, LocalDate borrowDate,LocalDate returnDate) + { + this.bookId=bookId; + this.borrowerId=borrowerId; + this.borrowDate=borrowDate; + this.returnDate=returnDate; + this.bookName = bookName; + this.transactionId = ++transactionCount; + } + + public void setTransactionCount(int transactionCount){ + this.transactionCount=transactionCount; + } public String getBookName() { return bookName;