From a4ce780b4e8604b669f423abe7b39bb67899b09a Mon Sep 17 00:00:00 2001 From: Adem Berber Date: Thu, 17 Feb 2022 22:13:33 +0100 Subject: [PATCH] Added Same Release Month Checker + Tests + Javadoc --- .../java/de/hs_fulda/ciip/projjpn/Games.java | 47 +++++++++++++++++++ .../de/hs_fulda/ciip/projjpn/GamesTest.java | 7 +++ 2 files changed, 54 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 994a3c0..9e433fa 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 @@ -1332,6 +1332,53 @@ public class Games { return result.substring(0, result.length() - 2); } + + /** + * Checks if the release years are all the same across Europe, Japan, North + * America and Australia. + * + * @return Prints the games which have the same release year. + */ + public String checkAllSameReleaseMonth() { + String result = ""; + String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU FROM Games"; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gameName = resultSet.getString("Game_Name"); + String gameReleaseEu = resultSet.getString("Game_Release_EU"); + String gameReleaseJp = resultSet.getString("Game_Release_JP"); + String gameReleaseNa = resultSet.getString("Game_Release_NA"); + String gameReleaseAu = resultSet.getString("Game_Release_AU"); + + if (gameReleaseAu == null) { + + } else { + if (gameReleaseEu.substring(5, 7).equals(gameReleaseJp.substring(5, 7)) + && gameReleaseJp.substring(5, 7).equals(gameReleaseNa.substring(5, 7)) + && gameReleaseEu.substring(5, 7).equals(gameReleaseNa.substring(5, 7)) + && gameReleaseAu.substring(5, 7).equals(gameReleaseEu.substring(5, 7)) + && gameReleaseAu.substring(5, 7).equals(gameReleaseJp.substring(5, 7)) + && gameReleaseAu.substring(5, 7).equals(gameReleaseNa.substring(5, 7))) { + result += gameName + ", "; + } + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } /** * Checks if the game is compatible with one player or more. 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 cfc7052..7e9107e 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 @@ -191,6 +191,13 @@ public class GamesTest extends TestCase { String actual = testObject.checkAllDifferentReleaseYear(); assertEquals(expected, actual); } + + public void test_checkAllSameReleaseMonth() { + Games testObject = new Games(); + String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate, AI: The Somnium Files"; + String actual = testObject.checkAllSameReleaseMonth(); + assertEquals(expected, actual); + } public void test_checkOnePlayer() { Games testObject = new Games();