diff --git a/projjpn/GamesDB.accdb b/projjpn/GamesDB.accdb index ee44ae1..f0c11c0 100644 Binary files a/projjpn/GamesDB.accdb and b/projjpn/GamesDB.accdb differ diff --git a/projjpn/GamesDB.laccdb b/projjpn/GamesDB.laccdb index 5a03e03..e69de29 100644 Binary files a/projjpn/GamesDB.laccdb and b/projjpn/GamesDB.laccdb differ 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 fc1b27f..92078aa 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 @@ -9,7 +9,7 @@ import java.sql.Statement; public class Games { private String databaseURL = "jdbc:ucanaccess://GamesDB.accdb"; - public boolean checkForConnection() { + public boolean checkConnection() { try { Connection connection = DriverManager.getConnection(databaseURL); @@ -21,7 +21,7 @@ public class Games { } } - public String checkForConsoles() { + public String checkConsoles() { String result = ""; String query = "SELECT Game_Console FROM Games"; boolean ninSwitch = false; @@ -71,4 +71,70 @@ public class Games { // The substring removes the last New line in the String. return result.substring(0, result.length() - 2); } + + public String checkAllSamePublishers() { + String result = ""; + String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA 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 gamePublisherEu = resultSet.getString("Game_Publisher_EU"); + String gamePublisherJp = resultSet.getString("Game_Publisher_JP"); + String gamePublisherNa = resultSet.getString("Game_Publisher_NA"); + + + + if (gamePublisherEu.equals(gamePublisherJp) && gamePublisherJp.equals(gamePublisherNa) && gamePublisherEu.equals(gamePublisherNa)) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + // The substring removes the last New line in the String. + return result.substring(0, result.length() - 2); + } + + public String checkAllDifferentPublishers() { + String result = ""; + String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA 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 gamePublisherEu = resultSet.getString("Game_Publisher_EU"); + String gamePublisherJp = resultSet.getString("Game_Publisher_JP"); + String gamePublisherNa = resultSet.getString("Game_Publisher_NA"); + + + + if (!gamePublisherEu.equals(gamePublisherJp) && !gamePublisherJp.equals(gamePublisherNa) && !gamePublisherEu.equals(gamePublisherNa)) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + // The substring removes the last New line in the String. + 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 e57ae11..c6755a8 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 @@ -2,17 +2,31 @@ package de.hs_fulda.ciip.projjpn; import junit.framework.TestCase; public class GamesTest extends TestCase { - public void test_checkForConnection() { + public void test_checkConnection() { Games testObject = new Games(); boolean expected = true; - boolean actual = testObject.checkForConnection(); + boolean actual = testObject.checkConnection(); assertEquals(expected, actual); } - public void test_checkForConsoles() { + public void test_checkConsoles() { Games testObject = new Games(); String expected = "PlayStation 4, Multiplatform, Nintendo Switch, Nintendo DS, PlayStation 3, Xbox, PlayStation Portable, Nintendo 3DS, Xbox 360, PlayStation Vita"; - String actual = testObject.checkForConsoles(); + String actual = testObject.checkConsoles(); + assertEquals(expected, actual); + } + + public void test_checkAllSamePublishers() { + Games testObject = new Games(); + String expected = "Ratchet & Clank, Astral Chain, Fire Emblem: Three Houses, Rhythm Paradise, Super Smash Bros. Ultimate, Yakuza: Dead Souls, Jet Set Radio Future, Tomodachi Life, Beautiful Katamari, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkAllSamePublishers(); + assertEquals(expected, actual); + } + + public void test_checkAllDifferentPublishers() { + Games testObject = new Games(); + String expected = "Atelier Totori Plus"; + String actual = testObject.checkAllDifferentPublishers(); assertEquals(expected, actual); } }