From ea4247f42ebeeef68b04ebeb6e6018e94d9cad51 Mon Sep 17 00:00:00 2001 From: Adem Berber Date: Sat, 12 Feb 2022 02:51:36 +0100 Subject: [PATCH] Added Game Genre Checker + Test --- .../java/de/hs_fulda/ciip/projjpn/Games.java | 43 +++++++++++++++++++ .../de/hs_fulda/ciip/projjpn/GamesTest.java | 7 +++ 2 files changed, 50 insertions(+) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java index 165d0e7..04bb05b 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java @@ -249,4 +249,47 @@ public class Games { return result.substring(0, result.length() - 2); } + + public String checkGameGenres() { + String result = ""; + String query = "SELECT Game_Genre FROM Games"; + boolean actAd = false; + boolean rpg = false; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gameGenre = resultSet.getString("Game_Genre"); + + if (actAd && gameGenre.equals("Action-Adventure")) { + continue; + } else if (rpg && gameGenre.equals("RPG")) { + continue; + } + + switch (gameGenre) { + case "Action-Adventure": + actAd = true; + break; + case "RPG": + rpg = true; + break; + } + + result += gameGenre + ", "; + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java index 5acfde4..2f9fefc 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java @@ -51,4 +51,11 @@ public class GamesTest extends TestCase { String actual = testObject.checkAllDifferentReleaseDates(); assertEquals(expected, actual); } + + public void test_checkGameGenres() { + Games testObject = new Games(); + String expected = "JRPG, Action-Adventure, Tactical role-playing, Strategy, Rhythm, Fighting, Survival Horror, Action, Adventure, RPG, Life Simulation, Puzzle, Platformer"; + String actual = testObject.checkGameGenres(); + assertEquals(expected, actual); + } }