From 443c200c098032ed33e5ef81a649491d7310dfb8 Mon Sep 17 00:00:00 2001 From: Adem Berber Date: Sat, 12 Feb 2022 01:48:19 +0100 Subject: [PATCH] Added two Publisher checkers + Tests --- projjpn/GamesDB.accdb | Bin 1015808 -> 1015808 bytes projjpn/GamesDB.laccdb | Bin 64 -> 0 bytes .../java/de/hs_fulda/ciip/projjpn/Games.java | 70 +++++++++++++++++- .../de/hs_fulda/ciip/projjpn/GamesTest.java | 22 +++++- 4 files changed, 86 insertions(+), 6 deletions(-) diff --git a/projjpn/GamesDB.accdb b/projjpn/GamesDB.accdb index ee44ae17237edaa7eb3c2fad90e8305c9441c4c0..f0c11c07f60b3ee4e594324152aca738ce380672 100644 GIT binary patch delta 134 zcmZo@uxn_r+rY%f^n!V_0N)43$qIZtO#<5l7*FuAX1zLEpECWd9HS(oUHfx6Mj&Pa zVrC#_+5TLPReB+hC$~?SqYncR*fUHQIKY}UUEu($(DteWtP1SytB$h*F&hwr*c?F2 V3B+7L%nigmK+L;+)p5SC9ROODGZz2= delta 132 zcmZo@uxn_r+rY%fbc1=b0N)43$qIZtO#<5l7*FuA&Z{ipO`LvKj!}})to^whBM>tI zF*6XeY=17tD!q^=lG`WD(T4#D%o(N&9AM4a-gSUgfqmizf%a9$S%H`hh}nUd1Bf|+ Um94fYQ45771WG4%0wG-gmh1CA-VnRytZ2t@#)Zwp2M 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); } }