From b5ff15acd6d254cb4ebce6341990cbe5efe2db0a Mon Sep 17 00:00:00 2001 From: Adem Berber Date: Fri, 11 Feb 2022 03:12:47 +0100 Subject: [PATCH] Added Console Listing + Test --- projjpn/GamesDB.laccdb | Bin 0 -> 64 bytes .../java/de/hs_fulda/ciip/projjpn/Games.java | 53 ++++++++++++++++++ .../de/hs_fulda/ciip/projjpn/GamesTest.java | 7 +++ 3 files changed, 60 insertions(+) diff --git a/projjpn/GamesDB.laccdb b/projjpn/GamesDB.laccdb index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5a03e0388674df9c401c0cef4dc38d6267f63454 100644 GIT binary patch literal 64 icmZ>94fYQ45771WG4%0wG-gmh1CA-VnRytZ2t@#)Zwp2M literal 0 HcmV?d00001 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); + } }