diff --git a/projjpn/GamesDB.laccdb b/projjpn/GamesDB.laccdb index e69de29..5a03e03 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 09c31e9..fc1b27f 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 @@ -2,7 +2,9 @@ package de.hs_fulda.ciip.projjpn; import java.sql.Connection; import java.sql.DriverManager; +import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; public class Games { private String databaseURL = "jdbc:ucanaccess://GamesDB.accdb"; @@ -18,4 +20,55 @@ public class Games { return false; } } + + public String checkForConsoles() { + String result = ""; + String query = "SELECT Game_Console FROM Games"; + boolean ninSwitch = false; + boolean xbox = false; + boolean multiplat = false; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gameConsole = resultSet.getString("Game_Console"); + + if (ninSwitch && gameConsole.equals("Nintendo Switch")) { + continue; + } else if (xbox && gameConsole.equals("Xbox")) { + continue; + } else if (multiplat && gameConsole.equals("Multiplatform")) { + continue; + } + + switch (gameConsole) { + case "Nintendo Switch": + ninSwitch = true; + break; + case "Xbox": + xbox = true; + break; + case "Multiplatform": + multiplat = true; + break; + } + + + + result += gameConsole + ", "; + + } + 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 3ffaca8..e57ae11 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 @@ -8,4 +8,11 @@ public class GamesTest extends TestCase { boolean actual = testObject.checkForConnection(); assertEquals(expected, actual); } + + public void test_checkForConsoles() { + 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(); + assertEquals(expected, actual); + } }