diff --git a/projjpn/GamesDB.accdb b/projjpn/GamesDB.accdb new file mode 100644 index 0000000..1e9a2f9 Binary files /dev/null and b/projjpn/GamesDB.accdb differ diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java new file mode 100644 index 0000000..9ab68bf --- /dev/null +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java @@ -0,0 +1,67 @@ +package de.hs_fulda.ciip.projjpn; + +public class Birthdate { + private int day; + private int month; + private int year; + + public Birthdate(int d, int m, int y) { + day = d; + month = m; + year = y; + } + + public int getDay() { + return day; + } + + public int getMonth() { + return month; + } + + public int getYear() { + return year; + } + + /** + * @return Date Format DD.MM.YYYY + */ + public String toString() { + return day + "." + month + "." + year; + } + + /** + * + * @param d Day + * @param m Month + * @param y Year + */ + public void changeBirthdate(int d, int m, int y) { + day = d; + month = m; + year = y; + } + + /** + * + * @param DD + * @param MM + * @param YYYY + * @return true if date is valid. + * @return false if date is invalid. + */ + public boolean isValid(int DD, int MM, int YYYY) { + if (DD < 1 || DD > 31) { + return false; + } + if (MM < 1 || MM > 12) { + return false; + } + if (YYYY < 1990 || YYYY > 2022) { + return false; + } + + return true; + } + +} diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java new file mode 100644 index 0000000..e2fd71a --- /dev/null +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java @@ -0,0 +1,56 @@ +package de.hs_fulda.ciip.projjpn; + +import java.util.HashMap; + +public class Customers { + HashMap pool = new HashMap(); + + /** + * + * @param nickname Is the particular Nickname free to use? + * @return true if nickname is Available. + * @return false if nickname is Available. + */ + public boolean nickNameAvailable(String nickname) { + User u = pool.get(nickname); + if (null == u) { + return true; + } + return false; + } + + /** + * + * @param user New User to register. + * @return + */ + public User registerUser(User user) { + return pool.putIfAbsent(user.nickName, user); + } + + /** + * + * @param userNickname Delete a particular User with the given nickname + * @return null or the deleted user. + */ + public User deleteUser(String userNickname) { + return pool.remove(userNickname); + } + + /** + * + * @param nickname Find User by nickname + * @return + */ + public User getByNickname(String nickname) { + return pool.get(nickname); + } + + /** + * + * @return Number of Users. + */ + public int getCountOfUsers() { + return pool.size(); + } +} 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 new file mode 100644 index 0000000..38172d4 --- /dev/null +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java @@ -0,0 +1,2449 @@ +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"; + + /** + * Checks if the connection to the database can be established + * + * @return Returns true if it connects successfully and false if the connection + * fails. + */ + public boolean checkConnection() { + try { + Connection connection = DriverManager.getConnection(databaseURL); + + connection.close(); + return true; + + } catch (SQLException e) { + return false; + } + } + + /** + * Prints the whole table for those, who cannot access the Database for some + * reason. + * + * @return Returns a String of the whole table. + */ + public String printTable() { + String result = ""; + String query = "SELECT * FROM Games"; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + result += "Name, Console, Developer, Publisher EU, Publisher JP, Publisher NA, Genre, Release EU, Release JP, Release NA, Release AU, USK Rating, PEGI Rating, ESRB Rating, CERO Rating, ACB Rating, Players\n\n"; + + while (resultSet.next()) { + String gameName = resultSet.getString("Game_Name"); + String gameConsole = resultSet.getString("Game_Console"); + String gameDeveloper = resultSet.getString("Game_Developer"); + String gamePublisherEu = resultSet.getString("Game_Publisher_EU"); + String gamePublisherJp = resultSet.getString("Game_Publisher_JP"); + String gamePublisherNa = resultSet.getString("Game_Publisher_NA"); + String gameGenre = resultSet.getString("Game_Genre"); + + String gameReleaseEu = resultSet.getString("Game_Release_EU"); + String gameReleaseEuDots = gameReleaseEu.substring(8, 10) + "." + gameReleaseEu.substring(5, 7) + "." + + gameReleaseEu.substring(0, 4); + + String gameReleaseJp = resultSet.getString("Game_Release_JP"); + String gameReleaseJpDots = gameReleaseJp.substring(8, 10) + "." + gameReleaseJp.substring(5, 7) + "." + + gameReleaseJp.substring(0, 4); + + String gameReleaseNa = resultSet.getString("Game_Release_NA"); + String gameReleaseNaDots = gameReleaseNa.substring(8, 10) + "." + gameReleaseNa.substring(5, 7) + "." + + gameReleaseNa.substring(0, 4); + String gameReleaseAu = resultSet.getString("Game_Release_AU"); + String gameReleaseAuDots; + if (gameReleaseAu != null) { + gameReleaseAuDots = gameReleaseAu.substring(8, 10) + "." + gameReleaseAu.substring(5, 7) + "." + + gameReleaseAu.substring(0, 4); + } else { + gameReleaseAuDots = "Unknown"; + } + + int gameUsk = resultSet.getInt("Game_USK_Rating"); + int gamePegi = resultSet.getInt("Game_PEGI_Rating"); + String gameEsrb = resultSet.getString("Game_ESRB_Rating"); + String gameCero = resultSet.getString("Game_CERO_Rating"); + String gameAcb = resultSet.getString("Game_ACB_Rating"); + String gamePlayers = resultSet.getString("Game_Players"); + + if (gamePegi != 0) { + result += gameName + ", " + gameConsole + ", " + gameDeveloper + ", " + gamePublisherEu + ", " + + gamePublisherJp + ", " + gamePublisherNa + ", " + gameGenre + ", " + gameReleaseEuDots + + ", " + gameReleaseJpDots + ", " + gameReleaseNaDots + ", " + gameReleaseAuDots + ", " + + gameUsk + ", " + gamePegi + ", " + gameEsrb + ", " + gameCero + ", " + gameAcb + ", " + + gamePlayers + "\n"; + } else { + result += gameName + ", " + gameConsole + ", " + gameDeveloper + ", " + gamePublisherEu + ", " + + gamePublisherJp + ", " + gamePublisherNa + ", " + gameGenre + ", " + gameReleaseEuDots + + ", " + gameReleaseJpDots + ", " + gameReleaseNaDots + ", " + gameReleaseAuDots + ", " + + gameUsk + ", Unknown, " + gameEsrb + ", " + gameCero + ", " + gameAcb + ", " + gamePlayers + + "\n"; + } + + } + 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() - 1); + } + + /** + * Prints out all game names from the table. + * + * @return Returns a String with the game names + */ + public String checkGames() { + String result = ""; + String query = "SELECT Game_Name 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"); + + result += gameName + ", "; + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Prints out all of the consoles which are represented in the table. + * + * @return Returns a String with the consoles. + */ + public String checkConsoles() { + 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(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game has the same publishers across Europe, Japan and North + * America + * + * @return Prints the games, that have the same publishers. + */ + 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(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game has not the same publishers across Europe, Japan and North + * America + * + * @return Prints the games, that do not have the same publishers. + */ + 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(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the developers and the publishers are all the same. + * + * @return Prints the games, where publishers and developers are the same. + */ + public String checkAllDifferentPublishersDeveloper() { + String result = ""; + String query = "SELECT Game_Name, Game_Developer, 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 gameDeveloper = resultSet.getString("Game_Developer"); + 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) && gameDeveloper.equals(gamePublisherEu) + && gameDeveloper.equals(gamePublisherJp) && gameDeveloper.equals(gamePublisherNa)) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the release dates are all the same across Europe, Japan, North + * America and Australia. + * + * @return Prints the games which have the same release dates. + */ + public String checkAllSameReleaseDates() { + String result = ""; + String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU 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 gameReleaseEu = resultSet.getString("Game_Release_EU"); + String gameReleaseJp = resultSet.getString("Game_Release_JP"); + String gameReleaseNa = resultSet.getString("Game_Release_NA"); + String gameReleaseAu = resultSet.getString("Game_Release_AU"); + + if (gameReleaseAu == null) { + if (gameReleaseEu.equals(gameReleaseJp) && gameReleaseJp.equals(gameReleaseNa) + && gameReleaseEu.equals(gameReleaseNa)) { + result += gameName + ", "; + } + } else { + if (gameReleaseEu.equals(gameReleaseJp) && gameReleaseJp.equals(gameReleaseNa) + && gameReleaseEu.equals(gameReleaseNa) && gameReleaseAu.equals(gameReleaseEu) + && gameReleaseAu.equals(gameReleaseJp) && gameReleaseAu.equals(gameReleaseNa)) { + result += gameName + ", "; + } + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the release dates are not all the same across Europe, Japan, North + * America and Australia. + * + * @return Prints the games which do not have the same release dates. + */ + public String checkAllDifferentReleaseDates() { + String result = ""; + String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU 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 gameReleaseEu = resultSet.getString("Game_Release_EU"); + String gameReleaseJp = resultSet.getString("Game_Release_JP"); + String gameReleaseNa = resultSet.getString("Game_Release_NA"); + String gameReleaseAu = resultSet.getString("Game_Release_AU"); + + if (gameReleaseAu == null) { + if (!gameReleaseEu.equals(gameReleaseJp) && !gameReleaseJp.equals(gameReleaseNa) + && !gameReleaseEu.equals(gameReleaseNa)) { + result += gameName + ", "; + } + } else { + if (!gameReleaseEu.equals(gameReleaseJp) && !gameReleaseJp.equals(gameReleaseNa) + && !gameReleaseEu.equals(gameReleaseNa) && !gameReleaseAu.equals(gameReleaseEu) + && !gameReleaseAu.equals(gameReleaseJp) && !gameReleaseAu.equals(gameReleaseNa)) { + result += gameName + ", "; + } + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks the game genres that are available in the table + * + * @return Prints all the available game genres from the table. + */ + public String checkGameGenres() { + String result = ""; + String query = "SELECT Game_Genre FROM Games"; + boolean actAd = false; + boolean rpg = false; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gameGenre = resultSet.getString("Game_Genre"); + + if (actAd && gameGenre.equals("Action-Adventure")) { + continue; + } else if (rpg && gameGenre.equals("RPG")) { + continue; + } + + switch (gameGenre) { + case "Action-Adventure": + actAd = true; + break; + case "RPG": + rpg = true; + break; + } + + result += gameGenre + ", "; + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the games genre is Action-Adventure + * + * @return Prints all the Action-Adventure games. + */ + public String checkGameGenreActionAdventure() { + String result = ""; + String query = "SELECT Game_Name, Game_Genre 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 gameGenre = resultSet.getString("Game_Genre"); + + if (gameGenre.equals("Action-Adventure")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the games genre is RPG + * + * @return Prints all the RPG games. + */ + public String checkGameGenreRPG() { + String result = ""; + String query = "SELECT Game_Name, Game_Genre 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 gameGenre = resultSet.getString("Game_Genre"); + + if (gameGenre.equals("RPG")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Prints out all of the games which are on a PlayStation console. + * + * @return Returns a String with the games from a PlayStation console. + */ + public String checkConsolePlayStation() { + String result = ""; + String query = "SELECT Game_Name, Game_Console 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 gameConsole = resultSet.getString("Game_Console"); + + if (gameConsole.length() >= 11) { + if (gameConsole.substring(0, 11).equals("PlayStation")) { + result += gameName + ", "; + } + + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Prints out all of the games which are on a Nintendo console. + * + * @return Returns a String with the games from a Nintendo console. + */ + public String checkConsoleNintendo() { + String result = ""; + String query = "SELECT Game_Name, Game_Console 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 gameConsole = resultSet.getString("Game_Console"); + + if (gameConsole.length() >= 8) { + if (gameConsole.substring(0, 8).equals("Nintendo")) { + result += gameName + ", "; + } + + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Prints out all of the games which are on a Xbox console. + * + * @return Returns a String with the games from a Xbox console. + */ + public String checkConsoleXbox() { + String result = ""; + String query = "SELECT Game_Name, Game_Console 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 gameConsole = resultSet.getString("Game_Console"); + + if (gameConsole.length() >= 4) { + if (gameConsole.substring(0, 4).equals("Xbox")) { + result += gameName + ", "; + } + + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Prints out all of the games which are multiplatform. + * + * @return Returns a String with the multiplatform games . + */ + public String checkConsoleMultiplatform() { + String result = ""; + String query = "SELECT Game_Name, Game_Console 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 gameConsole = resultSet.getString("Game_Console"); + + if (gameConsole.length() >= 13) { + if (gameConsole.substring(0, 13).equals("Multiplatform")) { + result += gameName + ", "; + } + + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Prints out all of the games which are on a Nintendo Switch. + * + * @return Returns a String with the games from a Nintendo Switch. + */ + public String checkConsoleNintendoSwitch() { + String result = ""; + String query = "SELECT Game_Name, Game_Console 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 gameConsole = resultSet.getString("Game_Console"); + + if (gameConsole.equals("Nintendo Switch")) { + result += gameName + ", "; + + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the developer of the game is Atlus. + * + * @return Prints the games developed by Atlus. + */ + + public String checkDeveloperAtlus() { + String result = ""; + String query = "SELECT Game_Name, Game_Developer 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 gameDeveloper = resultSet.getString("Game_Developer"); + + if (gameDeveloper.equals("Atlus")) { + result += gameName + ", "; + + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks the developers that are available in the table. + * + * @return Prints the developers from the table. + */ + + public String checkDevelopers() { + String result = ""; + String query = "SELECT Game_Developer FROM Games"; + boolean atlus = false; + boolean nintendoSpd = false; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gameDeveloper = resultSet.getString("Game_Developer"); + + if (atlus && gameDeveloper.equals("Atlus")) { + continue; + } else if (nintendoSpd && gameDeveloper.equals("Nintendo SPD")) { + continue; + } + + switch (gameDeveloper) { + case "Atlus": + atlus = true; + break; + case "Nintendo SPD": + nintendoSpd = true; + break; + } + + result += gameDeveloper + ", "; + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game has the publisher Nintendo across Europe, Japan and North + * America + * + * @return Prints the games, that have Nintendo as a publisher. + */ + public String checkPublisherNintendo() { + 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("Nintendo") || gamePublisherJp.equals("Nintendo") + || gamePublisherNa.equals("Nintendo")) { + result += gameName + ", "; + + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game has the publisher Sega across Europe, Japan and North + * America + * + * @return Prints the games, that have Sega as a publisher. + */ + public String checkPublisherSega() { + 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("Sega") || gamePublisherJp.equals("Sega") + || gamePublisherNa.equals("Sega")) { + result += gameName + ", "; + + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks the publishers that are available in the table across Europe, Japan + * and North America + * + * @return Prints the publishers from Europe, Japan and North America. + */ + public String checkPublishers() { + String result = ""; + String query = "SELECT Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games"; + boolean sega = false; + boolean atlus = false; + boolean sce = false; + boolean nintendo = false; + boolean namco = false; + boolean spikeChun = false; + boolean bandaiNamco = false; + boolean activision = false; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gamePublisherEu = resultSet.getString("Game_Publisher_EU"); + String gamePublisherJp = resultSet.getString("Game_Publisher_JP"); + String gamePublisherNa = resultSet.getString("Game_Publisher_NA"); + + while (true) { + while (true) { + if (sega && gamePublisherEu.equals("Sega")) { + break; + } else if (atlus && gamePublisherEu.equals("Atlus")) { + break; + } else if (sce && gamePublisherEu.equals("Sony Computer Entertainment")) { + break; + } else if (nintendo && gamePublisherEu.equals("Nintendo")) { + break; + } else if (namco && gamePublisherEu.equals("Namco")) { + break; + } else if (spikeChun && gamePublisherEu.equals("Spike Chunsoft")) { + break; + } else if (bandaiNamco && gamePublisherEu.equals("Bandai Namco Games")) { + break; + } else if (activision && gamePublisherEu.equals("Activision")) { + break; + } + + switch (gamePublisherEu) { + case "Sega": + sega = true; + break; + case "Atlus": + atlus = true; + break; + case "Sony Computer Entertainment": + sce = true; + break; + case "Nintendo": + nintendo = true; + break; + case "Namco": + namco = true; + break; + case "Spike Chunsoft": + spikeChun = true; + break; + case "Bandai Namco Games": + bandaiNamco = true; + break; + case "Activision": + activision = true; + break; + } + + result += gamePublisherEu + ", "; + break; + } + if (sega && gamePublisherJp.equals("Sega")) { + break; + } else if (atlus && gamePublisherJp.equals("Atlus")) { + break; + } else if (sce && gamePublisherJp.equals("Sony Computer Entertainment")) { + break; + } else if (nintendo && gamePublisherJp.equals("Nintendo")) { + break; + } else if (namco && gamePublisherJp.equals("Namco")) { + break; + } else if (spikeChun && gamePublisherJp.equals("Spike Chunsoft")) { + break; + } else if (bandaiNamco && gamePublisherJp.equals("Bandai Namco Games")) { + break; + } else if (activision && gamePublisherJp.equals("Activision")) { + break; + } + + switch (gamePublisherJp) { + case "Sega": + sega = true; + break; + case "Atlus": + atlus = true; + break; + case "Sony Computer Entertainment": + sce = true; + break; + case "Nintendo": + nintendo = true; + break; + case "Namco": + namco = true; + break; + case "Spike Chunsoft": + spikeChun = true; + break; + case "Bandai Namco Games": + bandaiNamco = true; + break; + case "Activision": + activision = true; + break; + } + + result += gamePublisherJp + ", "; + break; + } + if (sega && gamePublisherNa.equals("Sega")) { + continue; + } else if (atlus && gamePublisherNa.equals("Atlus")) { + continue; + } else if (sce && gamePublisherNa.equals("Sony Computer Entertainment")) { + continue; + } else if (nintendo && gamePublisherNa.equals("Nintendo")) { + continue; + } else if (namco && gamePublisherNa.equals("Namco")) { + continue; + } else if (spikeChun && gamePublisherNa.equals("Spike Chunsoft")) { + continue; + } else if (bandaiNamco && gamePublisherNa.equals("Bandai Namco Games")) { + continue; + } else if (activision && gamePublisherNa.equals("Activision")) { + continue; + } + + switch (gamePublisherNa) { + case "Sega": + sega = true; + break; + case "Atlus": + atlus = true; + break; + case "Sony Computer Entertainment": + sce = true; + break; + case "Nintendo": + nintendo = true; + break; + case "Namco": + namco = true; + break; + case "Spike Chunsoft": + spikeChun = true; + break; + case "Bandai Namco Games": + bandaiNamco = true; + break; + case "Activision": + activision = true; + break; + } + + result += gamePublisherNa + ", "; + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks the publishers that are available in the table across Europe + * + * @return Prints the publishers from Europe. + */ + public String checkPublishersEu() { + String result = ""; + String query = "SELECT Game_Publisher_EU FROM Games"; + boolean sega = false; + boolean nintendo = false; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gamePublisherEu = resultSet.getString("Game_Publisher_EU"); + + if (sega && gamePublisherEu.equals("Sega")) { + continue; + } else if (nintendo && gamePublisherEu.equals("Nintendo")) { + continue; + } + + switch (gamePublisherEu) { + case "Sega": + sega = true; + break; + case "Nintendo": + nintendo = true; + break; + } + + result += gamePublisherEu + ", "; + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks the publishers that are available in the table across Japan + * + * @return Prints the publishers from Japan. + */ + public String checkPublishersJp() { + String result = ""; + String query = "SELECT Game_Publisher_JP FROM Games"; + boolean atlus = false; + boolean nintendo = false; + boolean sega = false; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gamePublisherJp = resultSet.getString("Game_Publisher_JP"); + + if (atlus && gamePublisherJp.equals("Atlus")) { + continue; + } else if (nintendo && gamePublisherJp.equals("Nintendo")) { + continue; + } else if (sega && gamePublisherJp.equals("Sega")) { + continue; + } + + switch (gamePublisherJp) { + case "Atlus": + atlus = true; + break; + case "Nintendo": + nintendo = true; + break; + case "Sega": + sega = true; + break; + } + + result += gamePublisherJp + ", "; + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks the publishers that are available in the table across North America + * + * @return Prints the publishers from North America. + */ + public String checkPublishersNa() { + String result = ""; + String query = "SELECT Game_Publisher_NA FROM Games"; + boolean atlus = false; + boolean nintendo = false; + boolean sega = false; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gamePublisherNa = resultSet.getString("Game_Publisher_Na"); + + if (atlus && gamePublisherNa.equals("Atlus")) { + continue; + } else if (nintendo && gamePublisherNa.equals("Nintendo")) { + continue; + } else if (sega && gamePublisherNa.equals("Sega")) { + continue; + } + + switch (gamePublisherNa) { + case "Atlus": + atlus = true; + break; + case "Nintendo": + nintendo = true; + break; + case "Sega": + sega = true; + break; + } + + result += gamePublisherNa + ", "; + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks the release dates that are unknown. + * + * @return Prints the games which do not have a release date. + */ + public String checkReleaseDateUnknown() { + String result = ""; + String query = "SELECT Game_Name, Game_Release_AU 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 gameReleaseAu = resultSet.getString("Game_Release_AU"); + + if (gameReleaseAu == null) { + + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the release years are all the same across Europe, Japan, North + * America and Australia. + * + * @return Prints the games which have the same release year. + */ + public String checkAllSameReleaseYear() { + String result = ""; + String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU 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 gameReleaseEu = resultSet.getString("Game_Release_EU"); + String gameReleaseJp = resultSet.getString("Game_Release_JP"); + String gameReleaseNa = resultSet.getString("Game_Release_NA"); + String gameReleaseAu = resultSet.getString("Game_Release_AU"); + + if (gameReleaseAu == null) { + + } else { + if (gameReleaseEu.substring(0, 4).equals(gameReleaseJp.substring(0, 4)) + && gameReleaseJp.substring(0, 4).equals(gameReleaseNa.substring(0, 4)) + && gameReleaseEu.substring(0, 4).equals(gameReleaseNa.substring(0, 4)) + && gameReleaseAu.substring(0, 4).equals(gameReleaseEu.substring(0, 4)) + && gameReleaseAu.substring(0, 4).equals(gameReleaseJp.substring(0, 4)) + && gameReleaseAu.substring(0, 4).equals(gameReleaseNa.substring(0, 4))) { + result += gameName + ", "; + } + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the release year are not all the same across Europe, Japan, North + * America and Australia. + * + * @return Prints the games which do not have the same release year. + */ + public String checkAllDifferentReleaseYear() { + String result = ""; + String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU 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 gameReleaseEu = resultSet.getString("Game_Release_EU"); + String gameReleaseJp = resultSet.getString("Game_Release_JP"); + String gameReleaseNa = resultSet.getString("Game_Release_NA"); + String gameReleaseAu = resultSet.getString("Game_Release_AU"); + + if (gameReleaseAu == null) { + result += gameName + ", "; + } else { + if (!gameReleaseEu.substring(0, 4).equals(gameReleaseJp.substring(0, 4)) + || !gameReleaseJp.substring(0, 4).equals(gameReleaseNa.substring(0, 4)) + || !gameReleaseEu.substring(0, 4).equals(gameReleaseNa.substring(0, 4)) + || !gameReleaseAu.substring(0, 4).equals(gameReleaseEu.substring(0, 4)) + || !gameReleaseAu.substring(0, 4).equals(gameReleaseJp.substring(0, 4)) + || !gameReleaseAu.substring(0, 4).equals(gameReleaseNa.substring(0, 4))) { + result += gameName + ", "; + } + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the release months are all the same across Europe, Japan, North + * America and Australia. + * + * @return Prints the games which have the same release month. + */ + public String checkAllSameReleaseMonth() { + String result = ""; + String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU 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 gameReleaseEu = resultSet.getString("Game_Release_EU"); + String gameReleaseJp = resultSet.getString("Game_Release_JP"); + String gameReleaseNa = resultSet.getString("Game_Release_NA"); + String gameReleaseAu = resultSet.getString("Game_Release_AU"); + + if (gameReleaseAu == null) { + + } else { + if (gameReleaseEu.substring(5, 7).equals(gameReleaseJp.substring(5, 7)) + && gameReleaseJp.substring(5, 7).equals(gameReleaseNa.substring(5, 7)) + && gameReleaseEu.substring(5, 7).equals(gameReleaseNa.substring(5, 7)) + && gameReleaseAu.substring(5, 7).equals(gameReleaseEu.substring(5, 7)) + && gameReleaseAu.substring(5, 7).equals(gameReleaseJp.substring(5, 7)) + && gameReleaseAu.substring(5, 7).equals(gameReleaseNa.substring(5, 7))) { + result += gameName + ", "; + } + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the release months are not all the same across Europe, Japan, North + * America and Australia. + * + * @return Prints the games which do not have the same release month. + */ + public String checkAllDifferentReleaseMonth() { + String result = ""; + String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU 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 gameReleaseEu = resultSet.getString("Game_Release_EU"); + String gameReleaseJp = resultSet.getString("Game_Release_JP"); + String gameReleaseNa = resultSet.getString("Game_Release_NA"); + String gameReleaseAu = resultSet.getString("Game_Release_AU"); + + if (gameReleaseAu == null) { + result += gameName + ", "; + } else { + if (!gameReleaseEu.substring(5, 7).equals(gameReleaseJp.substring(5, 7)) + || !gameReleaseJp.substring(5, 7).equals(gameReleaseNa.substring(5, 7)) + || !gameReleaseEu.substring(5, 7).equals(gameReleaseNa.substring(5, 7)) + || !gameReleaseAu.substring(5, 7).equals(gameReleaseEu.substring(5, 7)) + || !gameReleaseAu.substring(5, 7).equals(gameReleaseJp.substring(5, 7)) + || !gameReleaseAu.substring(5, 7).equals(gameReleaseNa.substring(5, 7))) { + result += gameName + ", "; + } + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is compatible with one player or more. + * + * @return Prints out the games that can be played with one or more players. + */ + 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); + } + + /** + * Checks if the game is compatible with two players or more. + * + * @return Prints out the games that can be played with two or more players. + */ + 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); + } + + /** + * Checks if the game is compatible with four players or more. + * + * @return Prints out the games that can be played with four or more players. + */ + public String checkFourPlayer() { + 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-4") || gamePlayers.equals("1-8")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is compatible with eight players + * + * @return Prints out the games that can be played with eight players. + */ + public String checkEightPlayer() { + 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-8")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is compatible with one player only. + * + * @return Prints out the games that can only be played alone. + */ + public String checkOnePlayerOnly() { + 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")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is USK 0 + * + * @return Prints all the USK 0 games. + */ + public String checkUskZero() { + String result = ""; + String query = "SELECT Game_Name, Game_USK_Rating 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"); + int gameUsk = resultSet.getInt("Game_USK_Rating"); + + if (gameUsk == 0) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is USK 6 + * + * @return Prints all the USK 6 games. + */ + public String checkUskSix() { + String result = ""; + String query = "SELECT Game_Name, Game_USK_Rating 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"); + int gameUsk = resultSet.getInt("Game_USK_Rating"); + + if (gameUsk == 6) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is USK 12 + * + * @return Prints all the USK 12 games. + */ + public String checkUskTwelve() { + String result = ""; + String query = "SELECT Game_Name, Game_USK_Rating 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"); + int gameUsk = resultSet.getInt("Game_USK_Rating"); + + if (gameUsk == 12) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is USK 16 + * + * @return Prints all the USK 16 games. + */ + public String checkUskSixteen() { + String result = ""; + String query = "SELECT Game_Name, Game_USK_Rating 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"); + int gameUsk = resultSet.getInt("Game_USK_Rating"); + + if (gameUsk == 16) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is USK 18 + * + * @return Prints all the USK 18 games. + */ + public String checkUskEighteen() { + String result = ""; + String query = "SELECT Game_Name, Game_USK_Rating 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"); + int gameUsk = resultSet.getInt("Game_USK_Rating"); + + if (gameUsk == 18) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is PEGI 3. + * + * @return Prints all the PEGI 3 games. + */ + public String checkPegiThree() { + String result = ""; + String query = "SELECT Game_Name, Game_PEGI_Rating 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"); + int gamePegi = resultSet.getInt("Game_PEGI_Rating"); + + if (gamePegi == 3) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is PEGI 7. + * + * @return Prints all the PEGI 7 games. + */ + public String checkPegiSeven() { + String result = ""; + String query = "SELECT Game_Name, Game_PEGI_Rating 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"); + int gamePegi = resultSet.getInt("Game_PEGI_Rating"); + + if (gamePegi == 7) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is PEGI 12. + * + * @return Prints all the PEGI 12 games. + */ + public String checkPegiTwelve() { + String result = ""; + String query = "SELECT Game_Name, Game_PEGI_Rating 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"); + int gamePegi = resultSet.getInt("Game_PEGI_Rating"); + + if (gamePegi == 12) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is PEGI 16. + * + * @return Prints all the PEGI 16 games. + */ + public String checkPegiSixteen() { + String result = ""; + String query = "SELECT Game_Name, Game_PEGI_Rating 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"); + int gamePegi = resultSet.getInt("Game_PEGI_Rating"); + + if (gamePegi == 16) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is PEGI 18. + * + * @return Prints all the PEGI 18 games. + */ + public String checkPegiEighteen() { + String result = ""; + String query = "SELECT Game_Name, Game_PEGI_Rating 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"); + int gamePegi = resultSet.getInt("Game_PEGI_Rating"); + + if (gamePegi == 18) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game has no PEGI rating. + * + * @return Prints all the games without a PEGI rating. + */ + public String checkPegiUnknown() { + String result = ""; + String query = "SELECT Game_Name, Game_PEGI_Rating 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"); + int gamePegi = resultSet.getInt("Game_PEGI_Rating"); + + if (gamePegi == 0) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is ESRB E. + * + * @return Prints all the ESRB E games. + */ + public String checkEsrbE() { + String result = ""; + String query = "SELECT Game_Name, Game_ESRB_Rating 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 gameEsrb = resultSet.getString("Game_ESRB_Rating"); + + if (gameEsrb.equals("E")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is ESRB E10+. + * + * @return Prints all the ESRB E10+ games. + */ + public String checkEsrbEten() { + String result = ""; + String query = "SELECT Game_Name, Game_ESRB_Rating 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 gameEsrb = resultSet.getString("Game_ESRB_Rating"); + + if (gameEsrb.equals("E10+")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is ESRB T. + * + * @return Prints all the ESRB T games. + */ + public String checkEsrbT() { + String result = ""; + String query = "SELECT Game_Name, Game_ESRB_Rating 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 gameEsrb = resultSet.getString("Game_ESRB_Rating"); + + if (gameEsrb.equals("T")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is ESRB M. + * + * @return Prints all the ESRB M games. + */ + public String checkEsrbM() { + String result = ""; + String query = "SELECT Game_Name, Game_ESRB_Rating 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 gameEsrb = resultSet.getString("Game_ESRB_Rating"); + + if (gameEsrb.equals("M")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is CERO A. + * + * @return Prints all the CERO A games. + */ + public String checkCeroA() { + String result = ""; + String query = "SELECT Game_Name, Game_CERO_Rating 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 gameCero = resultSet.getString("Game_CERO_Rating"); + + if (gameCero.equals("A")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is CERO B. + * + * @return Prints all the CERO B games. + */ + public String checkCeroB() { + String result = ""; + String query = "SELECT Game_Name, Game_CERO_Rating 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 gameCero = resultSet.getString("Game_CERO_Rating"); + + if (gameCero.equals("B")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is CERO C. + * + * @return Prints all the CERO C games. + */ + public String checkCeroC() { + String result = ""; + String query = "SELECT Game_Name, Game_CERO_Rating 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 gameCero = resultSet.getString("Game_CERO_Rating"); + + if (gameCero.equals("C")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is CERO D. + * + * @return Prints all the CERO D games. + */ + public String checkCeroD() { + String result = ""; + String query = "SELECT Game_Name, Game_CERO_Rating 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 gameCero = resultSet.getString("Game_CERO_Rating"); + + if (gameCero.equals("D")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is CERO Z. + * + * @return Prints all the CERO Z games. + */ + public String checkCeroZ() { + String result = ""; + String query = "SELECT Game_Name, Game_CERO_Rating 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 gameCero = resultSet.getString("Game_CERO_Rating"); + + if (gameCero.equals("Z")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is ACB G. + * + * @return Prints all the ACB G games. + */ + public String checkAcbG() { + String result = ""; + String query = "SELECT Game_Name, Game_ACB_Rating 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 gameAcb = resultSet.getString("Game_ACB_Rating"); + + if (gameAcb.equals("G")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is ACB PG. + * + * @return Prints all the ACB PG games. + */ + public String checkAcbPg() { + String result = ""; + String query = "SELECT Game_Name, Game_ACB_Rating 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 gameAcb = resultSet.getString("Game_ACB_Rating"); + + if (gameAcb.equals("PG")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is ACB M. + * + * @return Prints all the ACB M games. + */ + public String checkAcbM() { + String result = ""; + String query = "SELECT Game_Name, Game_ACB_Rating 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 gameAcb = resultSet.getString("Game_ACB_Rating"); + + if (gameAcb.equals("M")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is ACB MA 15+. + * + * @return Prints all the ACB MA 15+ games. + */ + public String checkAcbMaFifteen() { + String result = ""; + String query = "SELECT Game_Name, Game_ACB_Rating 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 gameAcb = resultSet.getString("Game_ACB_Rating"); + + if (gameAcb.equals("MA 15+")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } + + /** + * Checks if the game is ACB R 18+. + * + * @return Prints all the ACB R 18+ games. + */ + public String checkAcbReighteen() { + String result = ""; + String query = "SELECT Game_Name, Game_ACB_Rating 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 gameAcb = resultSet.getString("Game_ACB_Rating"); + + if (gameAcb.equals("R 18+")) { + result += gameName + ", "; + } + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return result.substring(0, result.length() - 2); + } +} diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java new file mode 100644 index 0000000..1be3965 --- /dev/null +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java @@ -0,0 +1,88 @@ +package de.hs_fulda.ciip.projjpn; + +public class Item { + + private String productTitle; + private String description; + private int availability = 0; + private float price; + + /** + * Creation of blank Item. + */ + public Item() { + } + + /** + * Creation of Item. + * @param titel + * @param description + * @param quantity + * @param price + */ + public Item(String titel, + String description, + int quantity, + float price) { + this.productTitle = titel; + this.description = description; + this.availability = quantity; + this.price = price; + } + + /** + * + * @return true if at least one item is in stock. + */ + public boolean inStock() { + return availability > 0; + } + + /** + * + * @return current number of this items + */ + public float getCurrentStock() { + return availability; + } + + /** + * + * @param newAmount of items + */ + public void updateAvailability(int newAmount) { + availability = newAmount; + } + + /** + * + * @param newPrice of this item. + */ + public void updatePrice(float newPrice) { + this.price = newPrice; + } + + /** + * + * @return Current Price of the Item. + */ + public float getCurrentPrice() { + return price; + } + + /** + * + * @return Current public Title of this Item. + */ + public String getTitel() { + return this.productTitle; + } + + /** + * + * @return Current public Description of this Item. + */ + public String getDescription() { + return this.description; + } +} diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java new file mode 100644 index 0000000..710e097 --- /dev/null +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java @@ -0,0 +1,41 @@ +package de.hs_fulda.ciip.projjpn; + +public class User { + String firstName; + String lastName; + String nickName; + String eMail; + Birthdate birthdate; + + public User(String firstName, + String lastName, + String nickName, + String eMail, + Birthdate birthdate) { + this.firstName = firstName; + this.lastName = lastName; + this.nickName = nickName; + this.eMail = eMail; + this.birthdate = birthdate; + } + + public User(String nickName) { + this.nickName = nickName; + } + + public String getFirstName() { + return firstName; + } + public String getLastName() { + return lastName; + } + public String getNickName() { + return nickName; + } + public String getEMail() { + return eMail; + } + public Birthdate getBirthdate() { + return birthdate; + } +} diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Warehouse.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Warehouse.java new file mode 100644 index 0000000..c0fd4fa --- /dev/null +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Warehouse.java @@ -0,0 +1,28 @@ +package de.hs_fulda.ciip.projjpn; + +import java.util.HashMap; + +public class Warehouse { + protected HashMap pool = new HashMap(); + + /** + * + * @param item Item to insert. + * @return the inserted Item or null. + */ + public Item insertItem(Item item) { + return pool.putIfAbsent(item.getTitel(), item); + } + + /** + * + * @return The total amount of all Items. + */ + public int getCountOfStock() { + int sumItems = 0; + for (HashMap.Entry set : pool.entrySet()) { + sumItems += set.getValue().getCurrentStock(); + } + return sumItems; + } +} \ No newline at end of file diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/AppTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/AppTest.java index a5ea653..8d0a135 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/AppTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/AppTest.java @@ -35,4 +35,8 @@ public class AppTest { assertTrue( true ); } + + public void testJenkins() { + assertTrue( true ); + } } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java new file mode 100644 index 0000000..b584b58 --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java @@ -0,0 +1,63 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class BirthdateTest extends TestCase { + + public void testToString() { + + // Given + Birthdate b = new Birthdate(1, 1, 2000); + + // When + String expectedDate = "1.1.2000"; + + // Then + assertEquals(expectedDate, b.toString()); + } + + public void test_changeBirthdate() { + // Given + Birthdate b = new Birthdate(1, 1, 2000); + + // Change Birthdate + b.changeBirthdate(2, 3, 2001); + + // When + int expectedDay = 2; + int expectedMonth = 3; + int expectedYear = 2001; + + // Then + assertEquals(2, b.getDay()); + assertEquals(3, b.getMonth()); + assertEquals(2001, b.getYear()); + } + + public void test_rejectInvalidBirthday() { + Birthdate birthdate = new Birthdate(0, 0, 0); + boolean expectedResult = false; + boolean gotResult = birthdate.isValid(0, 0, 0); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(32, 13, 1990); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(31, 0, 1980); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(31, 13, 1980); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(1, 1, 3000); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(1, 1, 1900); + assertEquals(expectedResult, gotResult); + + expectedResult = true; + gotResult = birthdate.isValid(1, 5, 2020); + assertEquals(expectedResult, gotResult); + } + +} diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java new file mode 100644 index 0000000..6dc92c3 --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java @@ -0,0 +1,177 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class CustomersTest extends TestCase { + + public void test_nicknameIsFree() { + // Given + Customers customers = new Customers(); + String availableNickname = "beastMaster64"; + + // When + boolean nicknameIsAvailable = customers.nickNameAvailable(availableNickname); + + // Then + assertTrue(nicknameIsAvailable); + } + + /** + * Register a user only when the given nickname is available. + */ + public void test_nicknameIsTaken() { + // Given + Customers customers = new Customers(); + String availableNickname = "beastMaster64"; + String takenNickname = "beastMaster64"; + User userToRegister = new User(availableNickname); + + customers.registerUser(userToRegister); + + // When + boolean nicknameIsTaken = customers.nickNameAvailable(availableNickname); + + // Then + assertFalse(nicknameIsTaken); + } + + /** + * Register a single user and check whether it worked. + */ + public void test_registerSingleUser() { + // Given + Customers customers = new Customers(); + String expectedNickNameInput = "Mougli"; + User expectedNewUser = new User(expectedNickNameInput); + + // Add a user + customers.registerUser(expectedNewUser); + + // Get the expected User + User expectedUser = customers.getByNickname(expectedNickNameInput); + // + assertNotNull(expectedNewUser); + String expectedNickNameGotBack = expectedUser.nickName; + + // When + boolean userRegistered = expectedNickNameGotBack.equals(expectedNickNameInput); + + // Then + assertTrue(userRegistered); + } + + /** + * Register multiple Users and then search for them in the same order. + */ + public void test_registerMultipleUsers() { + // Given + Customers customers = new Customers(); + String[] expectedNickNamesInput = {"Mougli", "Tarkan", "beastMaster64", "BlaBlaPew", "MuchDoge_321"}; + User[] expectedNewUsers = new User[expectedNickNamesInput.length]; + + for (int i = 0; i < expectedNickNamesInput.length; i++) { + // Create user + expectedNewUsers[i] = new User(expectedNickNamesInput[i]); + + // Add user + customers.registerUser(expectedNewUsers[i]); + } + + // Get the expected Users + User foundUser; + String expectedNickNameGotBack; + boolean userRegistered; + + for (int i = 0; i < expectedNickNamesInput.length; i++) { + // Get user + foundUser = customers.getByNickname(expectedNickNamesInput[i]); + assertNotNull(foundUser); + + // When + expectedNickNameGotBack = foundUser.nickName; + userRegistered = expectedNickNameGotBack.equals(expectedNickNamesInput[i]); + + // Then + assertTrue(userRegistered); + } + } + + /** + * Test if deletion of an allready registered customer works. + */ + public void test_removeRegisteredUser() { + // Given + Customers customers = new Customers(); + String userToRemove = "beastMaster64"; + User userToRegister = new User("beastMaster64"); + customers.registerUser(userToRegister); + + // When + boolean userExists = customers.nickNameAvailable(userToRemove); + assertFalse(userExists); + + // Then + User removedUser = customers.deleteUser(userToRemove); + assertEquals(userToRemove, removedUser.nickName); + + } + + /** + * Register a given number of users. + */ + public void test_registerAndCountUsers() { + // Given + Customers customers = new Customers(); + int expectedRegisteredUsers = 20; + int actualRegisteredUsers = -1; + String nickname; + + // Prepare + for(int i = 0, j = 1; i < expectedRegisteredUsers; i++, j++) { + nickname = "beastMaster_" + j; + customers.registerUser(new User(nickname)); + } + actualRegisteredUsers = customers.getCountOfUsers(); + assertEquals(expectedRegisteredUsers, actualRegisteredUsers); + } + + /** + * Check if the Registration of a User works as intended. + */ + public void test_createRegisterAndCheckUserData() { + // Given + Customers customers = new Customers(); + + String firstName = "Mia"; + String lastName = "Muster"; + String nickName = "harley"; + String eMail = "mia@muster.de"; + Birthdate birthdate = new Birthdate(30, 12, 1997); + + User userToCheck = new User(firstName, lastName, nickName, eMail, birthdate); + + // Register User + customers.registerUser(userToCheck); + + User gotUser = customers.getByNickname(nickName); + + assertNotNull(gotUser); + + // When + boolean correctFirstName = "Mia".equals(gotUser.getFirstName()); + boolean correctLastName = "Muster".equals(gotUser.getLastName()); + boolean correctNickName = "harley".equals(gotUser.getNickName()); + boolean correctEMail = "mia@muster.de".equals(gotUser.getEMail()); + boolean correctBirthdate = birthdate.toString().equals(gotUser.birthdate.toString()); + + // Then + assertTrue(correctFirstName); + assertTrue(correctLastName); + assertTrue(correctNickName); + assertTrue(correctEMail); + assertTrue(correctBirthdate); + + } + + +} 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 new file mode 100644 index 0000000..c6a229d --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java @@ -0,0 +1,442 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class GamesTest extends TestCase { + public void test_checkConnection() { + Games testObject = new Games(); + boolean expected = true; + boolean actual = testObject.checkConnection(); + assertEquals(expected, actual); + } + + public void test_checkGames() { + 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.checkGames(); + assertEquals(expected, actual); + } + + 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.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); + } + + public void test_checkAllSamePublishersDeveloper() { + Games testObject = new Games(); + String expected = "Beautiful Katamari"; + String actual = testObject.checkAllDifferentPublishersDeveloper(); + assertEquals(expected, actual); + } + + public void test_checkAllSameReleaseDates() { + Games testObject = new Games(); + String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate"; + String actual = testObject.checkAllSameReleaseDates(); + assertEquals(expected, actual); + } + + public void test_checkAllDifferentReleaseDates() { + Games testObject = new Games(); + String expected = "Rhythm Paradise, Yakuza: Dead Souls, Breakdown, Persona 3 Portable, Beautiful Katamari, Atelier Totori Plus"; + String actual = testObject.checkAllDifferentReleaseDates(); + assertEquals(expected, actual); + } + + public void test_checkGameGenres() { + Games testObject = new Games(); + String expected = "JRPG, Action-Adventure, Tactical role-playing, Strategy, Rhythm, Fighting, Survival Horror, Action, Adventure, RPG, Life Simulation, Puzzle, Platformer"; + String actual = testObject.checkGameGenres(); + assertEquals(expected, actual); + } + + public void test_checkGameGenreActionAdventure() { + Games testObject = new Games(); + String expected = "Ratchet & Clank, Astral Chain, Breakdown"; + String actual = testObject.checkGameGenreActionAdventure(); + assertEquals(expected, actual); + } + + public void test_checkGameGenreRPG() { + Games testObject = new Games(); + String expected = "Persona 3 Portable, Atelier Totori Plus"; + String actual = testObject.checkGameGenreRPG(); + assertEquals(expected, actual); + } + + public void test_checkConsolePlayStation() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Yakuza: Dead Souls, Persona 3 Portable, Atelier Totori Plus"; + String actual = testObject.checkConsolePlayStation(); + assertEquals(expected, actual); + } + + public void test_checkConsoleNintendo() { + Games testObject = new Games(); + String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Rhythm Paradise, Super Smash Bros. Ultimate, Tomodachi Life"; + String actual = testObject.checkConsoleNintendo(); + assertEquals(expected, actual); + } + + public void test_checkConsoleXbox() { + Games testObject = new Games(); + String expected = "Jet Set Radio Future, Breakdown, Beautiful Katamari"; + String actual = testObject.checkConsoleXbox(); + assertEquals(expected, actual); + } + + public void test_checkConsoleMultiplatform() { + Games testObject = new Games(); + String expected = "Ratchet & Clank, AI: The Somnium Files, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkConsoleMultiplatform(); + assertEquals(expected, actual); + } + + public void test_checkConsoleNintendoSwitch() { + Games testObject = new Games(); + String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate"; + String actual = testObject.checkConsoleNintendoSwitch(); + assertEquals(expected, actual); + } + + public void test_checkDeveloperAtlus() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Persona 3 Portable"; + String actual = testObject.checkDeveloperAtlus(); + assertEquals(expected, actual); + } + + public void test_checkDevelopers() { + Games testObject = new Games(); + String expected = "Atlus, Insomniac Games, Platinum Games, Intelligent Systems, Artdink, Nintendo SPD, Sora Ltd., Ryu Ga Gotoku Studio, Sega Sports R&D, Namco, Spike Chunsoft, Bandai Namco Games, Gust Co. Ltd., Vicarious Visions"; + String actual = testObject.checkDevelopers(); + assertEquals(expected, actual); + } + + public void test_checkPublisherNintendo() { + Games testObject = new Games(); + String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Rhythm Paradise, Super Smash Bros. Ultimate, Tomodachi Life"; + String actual = testObject.checkPublisherNintendo(); + assertEquals(expected, actual); + } + + public void test_checkPublisherSega() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Yakuza: Dead Souls, Jet Set Radio Future"; + String actual = testObject.checkPublisherSega(); + assertEquals(expected, actual); + } + + public void test_checkPublishers() { + Games testObject = new Games(); + String expected = "Sega, Atlus, Sony Computer Entertainment, Nintendo, Square Enix, Electronic Arts, Namco, Numskull Games, Spike Chunsoft, Ghostlight, Bandai Namco Games, Tecmo Koei Europe, Gust Co. Ltd., Tecmo Koei America, Activision"; + String actual = testObject.checkPublishers(); + assertEquals(expected, actual); + } + + public void test_checkPublishersEu() { + Games testObject = new Games(); + String expected = "Sega, Sony Computer Entertainment, Nintendo, Electronic Arts, Numskull Games, Ghostlight, Bandai Namco Games, Tecmo Koei Europe, Activision"; + String actual = testObject.checkPublishersEu(); + assertEquals(expected, actual); + } + + public void test_checkPublishersJp() { + Games testObject = new Games(); + String expected = "Atlus, Sony Computer Entertainment, Nintendo, Square Enix, Sega, Namco, Spike Chunsoft, Bandai Namco Games, Gust Co. Ltd., Activision"; + String actual = testObject.checkPublishersJp(); + assertEquals(expected, actual); + } + + public void test_checkPublishersNa() { + Games testObject = new Games(); + String expected = "Atlus, Sony Computer Entertainment, Nintendo, Sega, Namco, Spike Chunsoft, Bandai Namco Games, Tecmo Koei America, Activision"; + String actual = testObject.checkPublishersNa(); + assertEquals(expected, actual); + } + + public void test_checkReleaseDateUnknown() { + Games testObject = new Games(); + String expected = "Breakdown, Atelier Totori Plus"; + String actual = testObject.checkReleaseDateUnknown(); + assertEquals(expected, actual); + } + + public void test_checkAllSameReleaseYear() { + Games testObject = new Games(); + String expected = "Ratchet & Clank, Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate, Jet Set Radio Future, AI: The Somnium Files, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkAllSameReleaseYear(); + assertEquals(expected, actual); + } + + public void test_checkAllDifferentReleaseYear() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Rhythm Paradise, Yakuza: Dead Souls, Breakdown, Persona 3 Portable, Tomodachi Life, Beautiful Katamari, Atelier Totori Plus"; + String actual = testObject.checkAllDifferentReleaseYear(); + assertEquals(expected, actual); + } + + public void test_checkAllSameReleaseMonth() { + Games testObject = new Games(); + String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate, AI: The Somnium Files"; + String actual = testObject.checkAllSameReleaseMonth(); + assertEquals(expected, actual); + } + + public void test_checkAllDifferentReleaseMonth() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Ratchet & Clank, Rhythm Paradise, Yakuza: Dead Souls, Jet Set Radio Future, Breakdown, Persona 3 Portable, Tomodachi Life, Beautiful Katamari, Atelier Totori Plus, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkAllDifferentReleaseMonth(); + 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); + } + + public void test_checkFourPlayer() { + Games testObject = new Games(); + String expected = "Super Smash Bros. Ultimate, Jet Set Radio Future"; + String actual = testObject.checkFourPlayer(); + assertEquals(expected, actual); + } + + public void test_checkEightPlayer() { + Games testObject = new Games(); + String expected = "Super Smash Bros. Ultimate"; + String actual = testObject.checkEightPlayer(); + assertEquals(expected, actual); + } + + public void test_checkOnePlayerOnly() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Ratchet & Clank, Fire Emblem: Three Houses, Triangle Strategy, Rhythm Paradise, Yakuza: Dead Souls, Breakdown, AI: The Somnium Files, Persona 3 Portable, Tomodachi Life, Beautiful Katamari, Atelier Totori Plus, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkOnePlayerOnly(); + assertEquals(expected, actual); + } + + public void test_checkUskZero() { + Games testObject = new Games(); + String expected = "Rhythm Paradise, Tomodachi Life, Beautiful Katamari"; + String actual = testObject.checkUskZero(); + assertEquals(expected, actual); + } + + public void test_checkUskSix() { + Games testObject = new Games(); + String expected = "Ratchet & Clank, Atelier Totori Plus, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkUskSix(); + assertEquals(expected, actual); + } + + public void test_checkUskTwelve() { + Games testObject = new Games(); + String expected = "Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate, Jet Set Radio Future, Persona 3 Portable"; + String actual = testObject.checkUskTwelve(); + assertEquals(expected, actual); + } + + public void test_checkUskSixteen() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Astral Chain, Breakdown, AI: The Somnium Files"; + String actual = testObject.checkUskSixteen(); + assertEquals(expected, actual); + } + + public void test_checkUskEighteen() { + Games testObject = new Games(); + String expected = "Yakuza: Dead Souls"; + String actual = testObject.checkUskEighteen(); + assertEquals(expected, actual); + } + + public void test_checkPegiThree() { + Games testObject = new Games(); + String expected = "Ratchet & Clank, Rhythm Paradise, Tomodachi Life, Beautiful Katamari"; + String actual = testObject.checkPegiThree(); + assertEquals(expected, actual); + } + + public void test_checkPegiSeven() { + Games testObject = new Games(); + String expected = "Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkPegiSeven(); + assertEquals(expected, actual); + } + + public void test_checkPegiTwelve() { + Games testObject = new Games(); + String expected = "Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate, Persona 3 Portable, Atelier Totori Plus"; + String actual = testObject.checkPegiTwelve(); + assertEquals(expected, actual); + } + + public void test_checkPegiSixteen() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Astral Chain"; + String actual = testObject.checkPegiSixteen(); + assertEquals(expected, actual); + } + + public void test_checkPegiEighteen() { + Games testObject = new Games(); + String expected = "Yakuza: Dead Souls, Breakdown, AI: The Somnium Files"; + String actual = testObject.checkPegiEighteen(); + assertEquals(expected, actual); + } + + public void test_checkPegiUnknown() { + Games testObject = new Games(); + String expected = "Jet Set Radio Future"; + String actual = testObject.checkPegiUnknown(); + assertEquals(expected, actual); + } + + public void test_checkEsrbE() { + Games testObject = new Games(); + String expected = "Rhythm Paradise, Tomodachi Life, Beautiful Katamari"; + String actual = testObject.checkEsrbE(); + assertEquals(expected, actual); + } + + public void test_checkEsrbEten() { + Games testObject = new Games(); + String expected = "Super Smash Bros. Ultimate, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkEsrbEten(); + assertEquals(expected, actual); + } + + public void test_checkEsrbT() { + Games testObject = new Games(); + String expected = "Ratchet & Clank, Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Jet Set Radio Future, Atelier Totori Plus"; + String actual = testObject.checkEsrbT(); + assertEquals(expected, actual); + } + + public void test_checkEsrbM() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Yakuza: Dead Souls, Breakdown, AI: The Somnium Files, Persona 3 Portable"; + String actual = testObject.checkEsrbM(); + assertEquals(expected, actual); + } + + public void test_checkCeroA() { + Games testObject = new Games(); + String expected = "Ratchet & Clank, Rhythm Paradise, Super Smash Bros. Ultimate, Jet Set Radio Future, Tomodachi Life, Beautiful Katamari, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkCeroA(); + assertEquals(expected, actual); + } + + public void test_checkCeroB() { + Games testObject = new Games(); + String expected = "Fire Emblem: Three Houses, Persona 3 Portable, Atelier Totori Plus"; + String actual = testObject.checkCeroB(); + assertEquals(expected, actual); + } + + public void test_checkCeroC() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Astral Chain, Triangle Strategy, Breakdown"; + String actual = testObject.checkCeroC(); + assertEquals(expected, actual); + } + + public void test_checkCeroD() { + Games testObject = new Games(); + String expected = "Yakuza: Dead Souls"; + String actual = testObject.checkCeroD(); + assertEquals(expected, actual); + } + + public void test_checkCeroZ() { + Games testObject = new Games(); + String expected = "AI: The Somnium Files"; + String actual = testObject.checkCeroZ(); + assertEquals(expected, actual); + } + + public void test_checkAcbG() { + Games testObject = new Games(); + String expected = "Rhythm Paradise, Beautiful Katamari"; + String actual = testObject.checkAcbG(); + assertEquals(expected, actual); + } + + public void test_checkAcbPg() { + Games testObject = new Games(); + String expected = "Ratchet & Clank, Super Smash Bros. Ultimate, Tomodachi Life, Crash Bandicoot N. Sane Trilogy"; + String actual = testObject.checkAcbPg(); + assertEquals(expected, actual); + } + + public void test_checkAcbM() { + Games testObject = new Games(); + String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Jet Set Radio Future"; + String actual = testObject.checkAcbM(); + assertEquals(expected, actual); + } + + public void test_checkAcbMaFifteen() { + Games testObject = new Games(); + String expected = "Persona 5 Royal, Yakuza: Dead Souls, Breakdown, AI: The Somnium Files, Persona 3 Portable"; + String actual = testObject.checkAcbMaFifteen(); + assertEquals(expected, actual); + } + + public void test_checkAcbReighteen() { + Games testObject = new Games(); + String expected = "Atelier Totori Plus"; + String actual = testObject.checkAcbReighteen(); + assertEquals(expected, actual); + } + + public void test_printTable() { + Games testObject = new Games(); + String expected = "Name, Console, Developer, Publisher EU, Publisher JP, Publisher NA, Genre, Release EU, Release JP, Release NA, Release AU, USK Rating, PEGI Rating, ESRB Rating, CERO Rating, ACB Rating, Players\n" + + "\n" + + "Persona 5 Royal, PlayStation 4, Atlus, Sega, Atlus, Atlus, JRPG, 31.03.2020, 31.10.2019, 31.03.2020, 31.03.2020, 16, 16, M, C, MA 15+, 1\n" + + "Ratchet & Clank, Multiplatform, Insomniac Games, Sony Computer Entertainment, Sony Computer Entertainment, Sony Computer Entertainment, Action-Adventure, 08.11.2002, 03.12.2002, 04.11.2002, 08.11.2002, 6, 3, T, A, PG, 1\n" + + "Astral Chain, Nintendo Switch, Platinum Games, Nintendo, Nintendo, Nintendo, Action-Adventure, 30.08.2019, 30.08.2019, 30.08.2019, 30.08.2019, 16, 16, T, C, M, 1-2\n" + + "Fire Emblem: Three Houses, Nintendo Switch, Intelligent Systems, Nintendo, Nintendo, Nintendo, Tactical role-playing, 26.07.2019, 26.07.2019, 26.07.2019, 26.07.2019, 12, 12, T, B, M, 1\n" + + "Triangle Strategy, Nintendo Switch, Artdink, Nintendo, Square Enix, Nintendo, Strategy, 04.03.2022, 04.03.2022, 04.03.2022, 04.03.2022, 12, 12, T, C, M, 1\n" + + "Rhythm Paradise, Nintendo DS, Nintendo SPD, Nintendo, Nintendo, Nintendo, Rhythm, 01.05.2009, 31.07.2008, 05.04.2009, 04.06.2009, 0, 3, E, A, G, 1\n" + + "Super Smash Bros. Ultimate, Nintendo Switch, Sora Ltd., Nintendo, Nintendo, Nintendo, Fighting, 07.12.2018, 07.12.2018, 07.12.2018, 07.12.2018, 12, 12, E10+, A, PG, 1-8\n" + + "Yakuza: Dead Souls, PlayStation 3, Ryu Ga Gotoku Studio, Sega, Sega, Sega, Survival Horror, 16.03.2012, 09.06.2011, 13.03.2012, 15.03.2012, 18, 18, M, D, MA 15+, 1\n" + + "Jet Set Radio Future, Xbox, Sega Sports R&D, Sega, Sega, Sega, Action, 14.03.2002, 22.02.2002, 25.02.2002, 14.03.2002, 12, Unknown, T, A, M, 1-4\n" + + "Breakdown, Xbox, Namco, Electronic Arts, Namco, Namco, Action-Adventure, 18.06.2004, 29.01.2004, 16.03.2004, Unknown, 16, 18, M, C, MA 15+, 1\n" + + "AI: The Somnium Files, Multiplatform, Spike Chunsoft, Numskull Games, Spike Chunsoft, Spike Chunsoft, Adventure, 20.09.2019, 19.09.2019, 17.09.2019, 20.09.2019, 16, 18, M, Z, MA 15+, 1\n" + + "Persona 3 Portable, PlayStation Portable, Atlus, Ghostlight, Atlus, Atlus, RPG, 29.04.2011, 01.11.2009, 06.07.2010, 16.11.2011, 12, 12, M, B, MA 15+, 1\n" + + "Tomodachi Life, Nintendo 3DS, Nintendo SPD, Nintendo, Nintendo, Nintendo, Life Simulation, 06.06.2014, 18.04.2013, 06.06.2014, 07.06.2014, 0, 3, E, A, PG, 1\n" + + "Beautiful Katamari, Xbox 360, Bandai Namco Games, Bandai Namco Games, Bandai Namco Games, Bandai Namco Games, Puzzle, 29.02.2008, 16.10.2007, 18.10.2007, 07.03.2008, 0, 3, E, A, G, 1\n" + + "Atelier Totori Plus, PlayStation Vita, Gust Co. Ltd., Tecmo Koei Europe, Gust Co. Ltd., Tecmo Koei America, RPG, 20.03.2013, 29.11.2012, 19.03.2013, Unknown, 6, 12, T, B, R 18+, 1\n" + + "Crash Bandicoot N. Sane Trilogy, Multiplatform, Vicarious Visions, Activision, Activision, Activision, Platformer, 30.06.2017, 03.08.2017, 30.06.2017, 30.06.2017, 6, 7, E10+, A, PG, 1"; + String actual = testObject.printTable(); + assertEquals(expected, actual); + } +} diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java new file mode 100644 index 0000000..aaf8886 --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java @@ -0,0 +1,89 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class ItemTest extends TestCase { + /** + * No Items are in Stock. + * Check the inStock() Method. + */ + public void test_ItemNotInStock() { + // Given + Item item = new Item(); + + // When + boolean notInStock = item.inStock(); + + // Then + assertFalse(notInStock); + } + + /** + * Stock is not Empty. + * Check the inStock() Method. + */ + public void test_ItemInStock() { + // Given + Item item = new Item(); + item.updateAvailability(1); + // When + boolean inStock = item.inStock(); + + // Then + assertTrue(inStock); + } + + /** + * One and the same type of an item costs the same. + * check getCurrentPrice() + */ + public void test_priceOfMultipleIdenticalItems() { + // Given + Item item = new Item(); + int quantity = 3; + float price = 5; + item.updateAvailability(quantity); + item.updatePrice(price); + + // When + float expectedPrice = quantity * price; + + // Then + float actualPrice = 0; + for(int i = 0; i < quantity; i++) { + actualPrice += item.getCurrentPrice(); + } + + assertEquals(expectedPrice, actualPrice); + } + + /** + * Check if creating a complete item with all attributes works as intended. + */ + public void test_buildCompleteItem() { + // Given + String expectedTitel = "Logitec Maus"; + String expectedDescription = "Gaming Maus fuer Fortgeschrittene."; + int expectedQuantity = 10; + float expectedPrice = 69.99f; + + // When + Item itemNotNull = new Item(expectedTitel, expectedDescription, expectedQuantity, expectedPrice); + + // Then + assertNotNull(itemNotNull); + + // When + boolean validDescription = itemNotNull.getDescription().equals(expectedDescription); + assertTrue(validDescription); + + boolean validTitle = itemNotNull.getTitel().equals(expectedTitel); + assertTrue(validTitle); + + boolean validQuantity = itemNotNull.getCurrentStock() == expectedQuantity; + assertTrue(validQuantity); + + boolean validPrice = itemNotNull.getCurrentPrice() == expectedPrice; + assertTrue(validPrice); + } +} diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java new file mode 100644 index 0000000..5598b71 --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java @@ -0,0 +1,23 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class UserTest extends TestCase { + /** + * Create User with a valid Birthday and check whether it worked as intended. + */ + public void test_initAndGetBirthdayOfUser() { + // Given + Customers customers = new Customers(); + String firstName = "Mia"; + String lastName = "Muster"; + String nickName = "harley"; + String eMail = "mia@muster.de"; + int DD = 30, MM = 12, YYYY = 1997; + String expectedBirthdate = new Birthdate(DD, MM, YYYY).toString(); + + User userToCheck = new User(firstName, lastName, nickName, eMail, new Birthdate(DD, MM, YYYY)); + String gotBirthdate = userToCheck.getBirthdate().toString(); + boolean gotExpectedBirthdayBack = gotBirthdate.equals(expectedBirthdate); + } +} diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/WarehouseTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/WarehouseTest.java new file mode 100644 index 0000000..5b7234e --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/WarehouseTest.java @@ -0,0 +1,63 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class WarehouseTest extends TestCase { + /** + * Check if the insertion of an Item works properly. + */ + public void test_insertItemInWarehouse() { + // Given + Warehouse warehouse = new Warehouse(); + + String expectedTitel = "Logitec Maus"; + String expectedDescription = "Gaming Maus fuer Fortgeschrittene."; + int expectedQuantity = 10; + float expectedPrice = 69.69f; + + // When + Item expectedItem = new Item(expectedTitel, expectedDescription, expectedQuantity, expectedPrice); + assertNotNull(expectedItem); + warehouse.insertItem(expectedItem); + + Item gotItem = warehouse.pool.get(expectedTitel); + + // Then + assertEquals(expectedTitel, gotItem.getTitel()); + } + + /** + * Test the total Sum of Items in the whole Warehouse. + */ + public void test_growingCountOfItemsInWarehouse() { + // Given + Warehouse warehouse = new Warehouse(); + int unitsPerItemType = 3; + int expectedSize = 13; + for (int i = 0; i < expectedSize; i++) { + Item item = new Item("ItemDummy" + i, "DescriptionDummy" + i, unitsPerItemType, 12.0f); + warehouse.insertItem(item); + } + int expectedSum = expectedSize * unitsPerItemType; + int actualSumOfAllItems = warehouse.getCountOfStock(); + + // Then + assertEquals(expectedSum, actualSumOfAllItems); + } + + /** + * Empty Warehouse means there are a total of zero Items. + */ + public void test_emptyWarehouse() { + // Given + Warehouse warehouse = new Warehouse(); + + // When + int expectedSum = 0; + + // Then + int actualSumOfAllItems = warehouse.getCountOfStock(); + assertEquals(expectedSum, actualSumOfAllItems); + + } +}