From 89e569711467fd893ab93838178966597aa61cc3 Mon Sep 17 00:00:00 2001 From: Adem Berber Date: Mon, 14 Feb 2022 00:14:32 +0100 Subject: [PATCH] Added Player Checkers + Tests --- projjpn/GamesDB.laccdb | Bin 0 -> 64 bytes .../java/de/hs_fulda/ciip/projjpn/Games.java | 58 ++++++++++++++++++ .../de/hs_fulda/ciip/projjpn/GamesTest.java | 14 +++++ 3 files changed, 72 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 efbbe6e..e2aa307 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 @@ -1165,4 +1165,62 @@ public class Games { return result.substring(0, result.length() - 2); } + + public String checkOnePlayer() { + String result = ""; + String query = "SELECT Game_Name, Game_Players 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 gamePlayers = resultSet.getString("Game_Players"); + + if (gamePlayers.equals("1") || gamePlayers.equals("1-2") || gamePlayers.equals("1-4") || gamePlayers.equals("1-8")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + public String checkTwoPlayer() { + String result = ""; + String query = "SELECT Game_Name, Game_Players 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 gamePlayers = resultSet.getString("Game_Players"); + + if (gamePlayers.equals("1-2") || gamePlayers.equals("1-4") || gamePlayers.equals("1-8")) { + result += gameName + ", "; + } + + } + 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 ba270b2..2009338 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,4 +191,18 @@ public class GamesTest extends TestCase { String actual = testObject.checkAllDifferentReleaseYear(); assertEquals(expected, actual); } + + public void test_checkOnePlayer() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Ratchet & Clank, Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Rhythm Paradise, Super Smash Bros. Ultimate, Yakuza: Dead Souls, Jet Set Radio Future, Breakdown, AI: The Somnium Files, Persona 3 Portable, Tomodachi Life, Beautiful Katamari, Atelier Totori Plus, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkOnePlayer(); + assertEquals(expected, actual); + } + + public void test_checkTwoPlayer() { + Games testObject = new Games(); + String expected = "Astral Chain, Super Smash Bros. Ultimate, Jet Set Radio Future"; + String actual = testObject.checkTwoPlayer(); + assertEquals(expected, actual); + } }