Skip to content

Commit

Permalink
Merge pull request #38 from ahmedsiam0/fix-some-bugs
Browse files Browse the repository at this point in the history
Fix reviews and ratings and category related bugs and add program icon
  • Loading branch information
ahmedsiam0 authored Dec 23, 2023
2 parents 9acdc38 + ca4967f commit a007438
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 33 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Any code should follow [Google Java Style Guide](https://google.github.io/styleg
In summary:
- Class names should be UpperCamelCase (like `Order`, `Book`).
- Variable, method, attribute and parameter names should be lowerCamelCase (like `updateBook`, `quantity`, `publicationYear`).

## Attribution
<a href="https://www.flaticon.com/free-icons/library" title="library icons">Library icons created by Freepik - Flaticon</a>
Binary file added data/bookSceneAssets/library_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 14 additions & 10 deletions data/datafiles/books_data.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
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
12,,,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.,,,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
12,,,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.,,,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
12,,,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.,,,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
12,,,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.,,,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
12,,,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.,,,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
12,,,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.,,,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
12,,,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],,,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
12,,,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.,,,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
12,,,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.,,,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
12,,,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.,,,data/covers/10.jpg
ADVENTURE,,,
12,,,11,,,Testing,,,23ir,,,323,,,true,,,234,,,234,,,3irj,,,data/covers/11.jpg

12,,,12,,,ijowef,,,waefoij,,,234,,,true,,,123,,,412,,,joiajefw,,,data/covers/12.jpg
HORROR,,,
1 change: 1 addition & 0 deletions data/datafiles/customers_data.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
5,,,2,,,user1,,,user1,,,111
5,,,7,,,Ahmed,,,1234,,,010111111111
Empty file.
5 changes: 1 addition & 4 deletions data/datafiles/reviews_data.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
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
13,,,2,,,2,,,10,,,5,,,I love this book :)
11 changes: 9 additions & 2 deletions src/main/java/com/asu/librarysystem/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.ArrayList;
import java.util.Arrays;

import javafx.scene.shape.Path;

public class Book {
private static int idCounter = 0;
private final int id;
Expand Down Expand Up @@ -114,11 +116,14 @@ public void setDescription(String description) {

public void setCover(String path) {
File newCover = new File(path);
cover = new File("data/covers/" + id + ".jpg");

if (!newCover.exists()) {
System.out.println("Can't find file with path: " + path);
System.out.println("Book title: " + title);
System.out.println("Book id: " + id);
return;
}
cover = new File("data/covers/" + id + ".jpg");
try {
if (!newCover.toPath().equals(cover.toPath()))
Files.copy(newCover.toPath(), cover.toPath(), StandardCopyOption.REPLACE_EXISTING);
Expand All @@ -129,7 +134,9 @@ public void setCover(String path) {
}
}
public String getCoverPath() {
return cover.getAbsolutePath();
String rootPath = System.getProperty("user.dir");
String relativePath = cover.getAbsolutePath().substring(rootPath.length() + 1);
return relativePath;
}

public ArrayList<Category> getCategories() {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/asu/librarysystem/BookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,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(2, book.getId(), 1, "I don't love this book");
// Library.getReviewHandler().addReview(2, book.getId(), 1, "I don't love this book");
ArrayList<Integer> ratings = Library.getReviewHandler().getBookRatings(book.getId());
setRatings(ratings);

Expand Down Expand Up @@ -148,12 +148,16 @@ private void setProperties(String name, String author, String releaseDate,String
this.author.setText(authorAttribute.getText() + ": " + author);

String categoriesText = new String();
String category;
String category = new String();
for (Category cat : currentBook.getCategories()){
category = cat.toString();
categoriesText += category.substring(0, 1) + category.substring(1).toLowerCase() + ", ";
}
categories.setText("Categories: " + categoriesText.substring(0, categoriesText.length() - 2));
if (categoriesText.length() > 3) {
categories.setText("Categories: " + categoriesText.substring(0, categoriesText.length() - 2));
} else {
categories.setText("Categories: None");
}

Label releaseDateAttribute = new Label("Release Date");
releaseDateAttribute.setStyle("-fx-font-weight: bold;");
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/asu/librarysystem/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,8 @@ public static void readLibrary () {
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);
Review.setIdCounter(Integer.valueOf(parts1[0]));
reviewHandler.addReview(Integer.valueOf(parts1[1]), Integer.valueOf(parts1[2]), Integer.valueOf(parts1[3]), Integer.valueOf(parts1[4]), parts1[5]);
}

scanner4.close();
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/asu/librarysystem/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.io.FileInputStream;
import java.io.IOException;


import java.io.InputStream;
import java.util.ArrayList;

public class MainApplication extends Application {
Expand Down Expand Up @@ -43,8 +43,9 @@ public void start(Stage stage) throws IOException {

FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("Login.fxml"));
Scene scene = new Scene(fxmlLoader.load(),1280,720);
// Image icon =new Image("");
// stage.getIcons().add(icon);
InputStream stream = new FileInputStream("data/bookSceneAssets/library_icon.png");
Image icon = new Image(stream);
stage.getIcons().add(icon);
stage.setTitle("library");


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/asu/librarysystem/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public Review(Review review) {
public int getIdCounter(){
return idCounter;
}
public void setIdCounter(int idCounter){
this.idCounter=idCounter;
public static void setIdCounter(int idCounter){
Review.idCounter=idCounter;
}

public void setRating(int rating) {
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/com/asu/librarysystem/ReviewHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ public void addReview(int reviewerId, int bookId, int rating, String text) {
review = new Review(reviewerId, bookId, rating, text);

reviews.add(review);
if (!bookRatings.containsKey(bookId)) {
bookRatings.put(bookId, new ArrayList<Integer>());
for (int i = 0; i < 6; i++)
bookRatings.get(bookId).add(0);
}

initializeBookRating(bookId);

addBookRating(bookId, review.getRating());
}

Expand Down Expand Up @@ -66,6 +64,8 @@ public ArrayList<Review> getBookReviews(int bookId) {
* where the index is the rating and the value is the number of reviewers who gave this rating.
*/
public ArrayList<Integer> getBookRatings(int bookId) {
initializeBookRating(bookId);

return (new ArrayList<Integer>(bookRatings.get(bookId)));
}

Expand Down Expand Up @@ -122,4 +122,11 @@ public void addReview(Review review) {
public ArrayList<Review> getReviews(){
return reviews;
}
private void initializeBookRating(int bookId) {
if (!bookRatings.containsKey(bookId)) {
bookRatings.put(bookId, new ArrayList<Integer>());
for (int i = 0; i < 6; i++)
bookRatings.get(bookId).add(0);
}
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit a007438

Please sign in to comment.