Java Database Authentication System
Java Database Authentication System
When registering a new user, the application first calls 'cariData' to check if the email already exists in the database. If the email is found, a message 'Email already exsist!!' is displayed. If not, the 'register' method is invoked, which attempts to insert the email and password into the database. If insertion is successful, 'Account successfully registered' is printed, otherwise 'Failed to register' is displayed .
The game application deals with invalid user input through a switch-case construction during action choices in a battle. If a non-existent action number is entered, the default case triggers, displaying 'Invalid choice!' and prompts the user again for action input. The application does not proceed until a valid input is provided. This mechanism ensures the game loop continues correctly without executing invalid options, maintaining gameplay flow .
The login process verifies user credentials by first checking the email with 'cariData' method that executes a SQL query to find the user ID. If the ID is found, the 'authAkun' method is called, executing another SQL query to fetch the stored email and password for that user ID. It then compares the provided email and password with the retrieved values. If they match, 'Login Success' is returned; if not, it returns 'Incorrect email or password'. If no ID is found in the first query, 'Account is not registered yet' is printed .
The database connection initialization in the class 'DB' ensures the driver is available by using the static block to load the MySQL JDBC driver with 'Class.forName(JDBC_DRIVER)'. If this process fails, a 'ClassNotFoundException' is caught and a message 'Driver MySQL tidak ditemukan!' is printed along with the stack trace .
During a battle, the game handles player actions through a loop where the player can choose to attack, heal, or run via a console input. If the player attacks, they deal damage to the monster; if they heal, their health is increased; if they run, a message indicates the monster is chasing. After each player action, if the monster is still alive, it attacks the player. Victory is declared if the monster is defeated, or defeat if the player is killed. This design follows the Command Pattern, where player choices (commands) result in different methods being executed .
Polymorphism is utilized within the game through method overrides in subclasses of 'Character', specifically 'Player' and 'Monster'. Both classes override methods 'attack' and 'takeDamage', providing unique behaviors suited to each character type, such as 'Player' executing a 'powerful strike' and 'Monster' executing a 'vicious attack'. This polymorphism enables flexible interaction handling, where the same method call can produce different effects depending on the actual object type, enhancing extensibility and maintainability in character behavior implementation .
The application checks the user passwords by retrieving the stored password corresponding to the provided email using a SQL SELECT query. During the login attempt, after the application verifies the email and retrieves the associated password from the database, it directly compares this stored password with the one the user inputs using 'equals' method. This approach ensures that the actual stored password string must exactly match the input password string for a successful login attempt .
The 'SuperV' class facilitates user interaction by providing methods to retrieve user-input email and password via console input. It sets these inputs in instance variables and supports both login and registration operations by serving as a common superclass, from which both 'LoginExtendSuperV' and 'RegisterExtendSuperV' inherit. This design choice supports reusability by avoiding code duplication for input handling between these processes .
The choice of weapons and armor reflects user experience design by providing straightforward options with clear benefits, such as consistent damage bonuses across weapons and fixed defense values for armor. This simplicity ensures players can easily understand their impact on gameplay, encouraging engagement through accessible decision-making without requiring complex calculations or decisions. Automatically equipping selected items further streamlines the experience, reflecting a design focus on fluidity and player empowerment .
In the RPG game, weapons and armor mechanics enhance player capability. Weapons, when equipped by the player, increase attack power by adding their damage value to the player's base attack power. For example, choosing a weapon like a sword increases the player's attack power by the weapon's damage value plus a bonus. Armor reduces incoming damage during a battle; its 'defencePower' mitigates the damage taken from enemy attacks, which can prevent player death and extend survivability in combat. Thus, equipment choice directly influences battle outcomes .