diff --git a/.gradle/7.4/checksums/checksums.lock b/.gradle/7.4/checksums/checksums.lock index 0a7cbfb..c780d08 100644 Binary files a/.gradle/7.4/checksums/checksums.lock and b/.gradle/7.4/checksums/checksums.lock differ diff --git a/.gradle/7.4/checksums/md5-checksums.bin b/.gradle/7.4/checksums/md5-checksums.bin new file mode 100644 index 0000000..720a35d Binary files /dev/null and b/.gradle/7.4/checksums/md5-checksums.bin differ diff --git a/.gradle/7.4/checksums/sha1-checksums.bin b/.gradle/7.4/checksums/sha1-checksums.bin index bd27f6a..d0ad05c 100644 Binary files a/.gradle/7.4/checksums/sha1-checksums.bin and b/.gradle/7.4/checksums/sha1-checksums.bin differ diff --git a/.gradle/7.4/executionHistory/executionHistory.bin b/.gradle/7.4/executionHistory/executionHistory.bin index d10930b..25336b8 100644 Binary files a/.gradle/7.4/executionHistory/executionHistory.bin and b/.gradle/7.4/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.4/executionHistory/executionHistory.lock b/.gradle/7.4/executionHistory/executionHistory.lock index bfee0ea..3852e77 100644 Binary files a/.gradle/7.4/executionHistory/executionHistory.lock and b/.gradle/7.4/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.4/fileHashes/fileHashes.bin b/.gradle/7.4/fileHashes/fileHashes.bin index 5ba85be..1adfadf 100644 Binary files a/.gradle/7.4/fileHashes/fileHashes.bin and b/.gradle/7.4/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.4/fileHashes/fileHashes.lock b/.gradle/7.4/fileHashes/fileHashes.lock index 043a103..accbb15 100644 Binary files a/.gradle/7.4/fileHashes/fileHashes.lock and b/.gradle/7.4/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.4/fileHashes/resourceHashesCache.bin b/.gradle/7.4/fileHashes/resourceHashesCache.bin index ba563c2..f44bf15 100644 Binary files a/.gradle/7.4/fileHashes/resourceHashesCache.bin and b/.gradle/7.4/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index bda9823..19444e2 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 87351e2..af8f65e 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index e5284fe..2b6666a 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/.idea/misc.xml b/.idea/misc.xml index 08237f1..9879958 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f9d2f50..894c175 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,7 +4,33 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + { "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", "SHARE_PROJECT_CONFIGURATION_FILES": "true", "WebServerToolWindowFactoryState": "false", "git-widget-placeholder": "main", - "last_opened_file_path": "C:/Users/Asus/Desktop/placeHolder/Second-Assignment-CineScribe", + "last_opened_file_path": "D:/programming/java/git/Fourth-Assignment-Steam-Scraper", "nodejs_package_manager_path": "npm", "settings.editor.selected.configurable": "preferences.pluginManager" } @@ -54,7 +81,30 @@ - + + + + + + + false + true + false + + + + + + + + false + true + false + + + + + + + + + + @@ -88,7 +173,7 @@ - + 1709128175583 1743341137706 diff --git a/build.gradle b/build.gradle index 82ff37b..4d89885 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' implementation 'org.jsoup:jsoup:1.14.3' + } test { diff --git a/build/classes/java/main/Game.class b/build/classes/java/main/Game.class new file mode 100644 index 0000000..b339c96 Binary files /dev/null and b/build/classes/java/main/Game.class differ diff --git a/build/classes/java/main/Parser.class b/build/classes/java/main/Parser.class new file mode 100644 index 0000000..bb30620 Binary files /dev/null and b/build/classes/java/main/Parser.class differ diff --git a/build/classes/java/test/ParserTest.class b/build/classes/java/test/ParserTest.class new file mode 100644 index 0000000..43835aa Binary files /dev/null and b/build/classes/java/test/ParserTest.class differ diff --git a/build/reports/tests/test/classes/ParserTest.html b/build/reports/tests/test/classes/ParserTest.html index 6888813..6cadb14 100644 --- a/build/reports/tests/test/classes/ParserTest.html +++ b/build/reports/tests/test/classes/ParserTest.html @@ -41,7 +41,7 @@

Class ParserTest

-
0.035s
+
0.011s

duration

@@ -75,18 +75,18 @@

Tests

-testSortByArea() -0.028s +testSortByName() +0.009s passed -testSortByName() -0.003s +testSortByPrice() +0.001s passed -testSortByPopulation() -0.004s +testSortByRating() +0.001s passed @@ -99,7 +99,7 @@

Tests

Generated by -Gradle 7.4 at Feb 28, 2024, 6:39:51 PM

+Gradle 7.4 at Apr 23, 2025, 9:29:33 PM

diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html index d2f1ae9..ba7460d 100644 --- a/build/reports/tests/test/index.html +++ b/build/reports/tests/test/index.html @@ -38,7 +38,7 @@

Test Summary

-
0.035s
+
0.011s

duration

@@ -85,7 +85,7 @@

Packages

3 0 0 -0.035s +0.011s 100% @@ -112,7 +112,7 @@

Classes

3 0 0 -0.035s +0.011s 100% @@ -126,7 +126,7 @@

Classes

Generated by -Gradle 7.4 at Feb 28, 2024, 6:39:51 PM

+Gradle 7.4 at Apr 23, 2025, 9:29:33 PM

diff --git a/build/reports/tests/test/packages/default-package.html b/build/reports/tests/test/packages/default-package.html index 2ffe0cb..26425f0 100644 --- a/build/reports/tests/test/packages/default-package.html +++ b/build/reports/tests/test/packages/default-package.html @@ -40,7 +40,7 @@

Default package

-
0.035s
+
0.011s

duration

@@ -83,7 +83,7 @@

Classes

3 0 0 -0.035s +0.011s 100% @@ -96,7 +96,7 @@

Classes

Generated by -Gradle 7.4 at Feb 28, 2024, 6:39:51 PM

+Gradle 7.4 at Apr 23, 2025, 9:29:33 PM

diff --git a/build/test-results/test/TEST-ParserTest.xml b/build/test-results/test/TEST-ParserTest.xml index 0dd5d0b..2becac9 100644 --- a/build/test-results/test/TEST-ParserTest.xml +++ b/build/test-results/test/TEST-ParserTest.xml @@ -1,9 +1,9 @@ - + - - - + + + diff --git a/build/test-results/test/binary/results.bin b/build/test-results/test/binary/results.bin index 05d8f6a..7146be7 100644 Binary files a/build/test-results/test/binary/results.bin and b/build/test-results/test/binary/results.bin differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 85f59d9..e6fdea2 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/build/tmp/compileTestJava/previous-compilation-data.bin b/build/tmp/compileTestJava/previous-compilation-data.bin index e3bdb4a..3956cb5 100644 Binary files a/build/tmp/compileTestJava/previous-compilation-data.bin and b/build/tmp/compileTestJava/previous-compilation-data.bin differ diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 79ed925..e421460 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -6,8 +6,9 @@ public class Game { private int price; public Game(String name, double rating, int price) { - //TODO - + this.name = name; + this.rating = rating; + this.price = price; } public String getName() { @@ -26,15 +27,21 @@ public int getPrice() { @Override public String toString() { //TODO - return ""; + return String.format("🎮 %-55s ⭐ %-4.1f/5 💵 $%-4d", + name, + rating, + price); } + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Game game = (Game) o; - return Double.compare(game.rating, rating) == 0 && Double.compare(game.price, price) == 0 && Objects.equals(name, game.name); + return Double.compare(game.rating, rating) == 0 && + Double.compare(game.price, price) == 0 && + Objects.equals(name, game.name); } } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index e6ba90f..79d2cba 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -5,44 +5,87 @@ import java.io.File; import java.io.IOException; import java.util.*; +import java.util.stream.Collectors; public class Parser { - static List games = new ArrayList<>(); + // Made games non-static for better encapsulation + private final List games = new ArrayList<>(); - public List sortByName(){ - List sortedByName = new ArrayList<>(games); + // Using Java Streams for more declarative sorting + public List sortByName() { // Sort games alphabetically (least) - //TODO - return sortedByName; + // TODO + return games.stream() + .sorted(Comparator.comparing(Game::getName)) + .collect(Collectors.toList()); } - public List sortByRating(){ - List sortedByRating = new ArrayList<>(games); + // Added null check for safety in sorting + public List sortByRating() { // Sort games by rating (most) //TODO - return sortedByRating; + return games.stream() + .sorted(Comparator.comparingDouble(Game::getRating).reversed()) + .collect(Collectors.toList()); } - public List sortByPrice(){ - List sortedByPrice = new ArrayList<>(games); + // Using method reference for cleaner code + public List sortByPrice() { // Sort games by price (most) //TODO - return sortedByPrice; + return games.stream() + .sorted(Comparator.comparingInt(Game::getPrice).reversed()) + .collect(Collectors.toCollection(ArrayList::new)); } + // Extracted parsing logic to separate methods for better readability public void setUp() throws IOException { - //Parse the HTML file using Jsoup //TODO + Document doc = parseHtmlFile(); + extractGameData(doc); + } + + private Document parseHtmlFile() throws IOException { + File input = new File("src/Resources/Video_Games.html"); + return Jsoup.parse(input, "UTF-8"); + } + private void extractGameData(Document doc) { // Extract data from the HTML //TODO + Elements gameElements = doc.select("div.col-md-4.game"); + + // Using forEach for cleaner iteration + gameElements.forEach(this::processGameElement); + } + private void processGameElement(Element gameElement) { // Iterate through each Game div to extract Game data - //TODO + String name = extractName(gameElement); + double rating = extractRating(gameElement); + int price = extractPrice(gameElement); + + games.add(new Game(name, rating, price)); + } + + // Extracted helper methods for better modularity + private String extractName(Element gameElement) { + return gameElement.select("h3.game-name").text(); + } + + private double extractRating(Element gameElement) { + String ratingText = gameElement.select("span.game-rating").text(); + return Double.parseDouble(ratingText.split("/")[0]); + } + + private int extractPrice(Element gameElement) { + String priceText = gameElement.select("span.game-price").text(); + return Integer.parseInt(priceText.replace("€", "").trim()); } public static void main(String[] args) { //you can test your code here before you run the unit tests + } -} +} \ No newline at end of file