From 87c39dfc391212ec462aa57d34aebfd9eb096189 Mon Sep 17 00:00:00 2001 From: IB Date: Thu, 21 Dec 2023 19:43:27 +0200 Subject: [PATCH] fixed some bugs(IB) --- .idea/workspace.xml | 25 ++++++++----------- data/datafiles/discount_data.txt | 2 ++ data/datafiles/reviews_data.txt | 7 +++--- .../com/asu/librarysystem/BookController.java | 11 ++++---- .../asu/librarysystem/MainApplication.java | 4 +-- .../com/asu/librarysystem/ReviewHandler.java | 18 ++++++++++++- 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3c0a119..2017c6a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,25 +5,15 @@ - - - - - - + + + + + - - - - - - - - - diff --git a/data/datafiles/discount_data.txt b/data/datafiles/discount_data.txt index e69de29..e7bce7b 100644 --- a/data/datafiles/discount_data.txt +++ b/data/datafiles/discount_data.txt @@ -0,0 +1,2 @@ +Lucky0,,,50.0 +Lucky1,,,100.0 diff --git a/data/datafiles/reviews_data.txt b/data/datafiles/reviews_data.txt index 3768147..bc7ba88 100644 --- a/data/datafiles/reviews_data.txt +++ b/data/datafiles/reviews_data.txt @@ -1,3 +1,4 @@ -14,,,16,,,14,,,3,,,4,,,ghj -14,,,16,,,14,,,6,,,3,,,jjoo -14,,,16,,,14,,,2,,,5,,,hbjk +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/src/main/java/com/asu/librarysystem/BookController.java b/src/main/java/com/asu/librarysystem/BookController.java index 9dfc57d..df8a137 100644 --- a/src/main/java/com/asu/librarysystem/BookController.java +++ b/src/main/java/com/asu/librarysystem/BookController.java @@ -85,8 +85,9 @@ 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(2, book.getId(), 3, "I don't love this book"); -// c + Library.getReviewHandler().addReview(2, book.getId(), 1, "I don't love this book"); + ArrayList ratings = Library.getReviewHandler().getBookRatings(book.getId()); + setRatings(ratings); InputStream stream1 = new FileInputStream("data/bookSceneAssets/Rating_icons/1_star.png"); InputStream stream2 = new FileInputStream("data/bookSceneAssets/Rating_icons/2_stars.png"); @@ -387,7 +388,7 @@ private void showComments(ArrayList comments) throws FileNotFoundExcepti Label username = new Label(); - String name=null ; + // ArrayList borrowers = Library.getBorrowers(); // ArrayList customers = Library.getCustomers(); @@ -398,9 +399,9 @@ private void showComments(ArrayList comments) throws FileNotFoundExcepti // name= Library.searchCustomerByID(comment.getReviewerId()).getUserName(); // } - // name=Library.searchAccountById(comment.getReviewerId()).getUserName(); + String name=Library.searchAccountById(comment.getReviewerId()).getUserName(); - username.setText(String.valueOf(comment.getReviewerId()));//String.valueOf(comment.getReviewerId()) + username.setText(name);//String.valueOf(comment.getReviewerId()) username.setStyle("-fx-font-weight: 200;"); username.setStyle("-fx-font-size: 20px;"); diff --git a/src/main/java/com/asu/librarysystem/MainApplication.java b/src/main/java/com/asu/librarysystem/MainApplication.java index be12e46..ba8fe07 100644 --- a/src/main/java/com/asu/librarysystem/MainApplication.java +++ b/src/main/java/com/asu/librarysystem/MainApplication.java @@ -103,8 +103,8 @@ public static void main(String[] args) { // borrower.addTransaction(book3); // borrower.addTransaction(book5); // borrower.addTransaction(book9); -// -// Library.writeLibrary(); + + // Library.writeLibrary(); Library.readLibrary(); diff --git a/src/main/java/com/asu/librarysystem/ReviewHandler.java b/src/main/java/com/asu/librarysystem/ReviewHandler.java index f205728..ce70eb0 100644 --- a/src/main/java/com/asu/librarysystem/ReviewHandler.java +++ b/src/main/java/com/asu/librarysystem/ReviewHandler.java @@ -100,8 +100,24 @@ 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.getBookId(),review.getRating(),review.getText()); + addReview(review.getId(),review.getReviewerId(),review.getBookId(),review.getRating(),review.getText()); } public ArrayList getReviews(){ return reviews;