CST 4713 JSP Web Application Development JREX 3A
Fall 2023
Java Review 3: DB Solution
JAVA DATABASE INTEGRATION EXERCISE
Professor Gene Locklear
Problem Background
• In our previous exercise, we designed and implemented an enhanced model of combat between two
Pokémon. In this exercise, we will improve on that design by incorporating the ability to store Pokémon and
the results of their battles .
• Our task is to design a Java-MySQL program that provides a way to provide persistent
storage of our Pokémon combat model.
• This task is designed to:
• Refresh and Reinforce our understanding of Java Object-Oriented Programming techniques.
• Refresh our understanding of MySQL database creation.
• Develop our ability to store and recall data from a MySQL database using Java.
• Enhance our ability to create Java programs from a descriptive model.
Battle Algorithm
• Utilizing our previous model, we want to improve our Battle Algorithm by incorporating the ability for
Pokémon to use specific attack and defense strategies.
• Our enhanced battle algorithm considers the following:
• A battle consists of four rounds of fighting.
• Pokémon alternate either attacking or defending in each of the four rounds.
• The Attack Power, in an attack by a Pokémon, is a random percentage (0% to 100%) of the Base Attack
Value added to the Power of type of attack performed.
• The Defense Power, used by a defending Pokémon, is a random percentage (0% to 100%) of Base
Defense Value added to the Power of the type of defense performed.
• During each round, Pokémon randomly choose their type of Attack and Defense.
• Only the Pokémon that attacks can inflict damage on the defending Pokémon.
• To determine damage to a defending Pokémon, the Defense Power is subtracted from the Attack
Power. The difference is the damage to the defending Pokémon. If the resulting difference is negative,
it assigned a 0 value.
• The Pokémon, who after four rounds, has the highest health wins the battle.
• If the Pokemon health, for both, is the same the battle is a draw.
Program Structure
This is our database connection code
This is our database script
This is the MySQL connector
Database Schema
1 1
pokemon
HAS
M pokemon_record
Fights
M
pokemon_battles
Database Relations
pokemon
PokeName PokeSpecies PokeType PokeValue MaxHealth CurrentHealth BaseAttackValue BaseDefenseValue
pokemon_record
PokeName Wins Losses Draws
pokemon_battles
BattleID WinnerName LoserName WinnerSpecies LoserSpecies
Database Relations
DatabaseSupport Class
Persistent Pokemon Storage
<Abstract>
Pokemon
-name: String -baseAttackValue: int
-pokeType: PokemonType -baseDefenseValue: int
-pokeSpecies -wins: int
-pokeValue: int -losses: int
-maxHealth: int -draws: int
-currentHealth: int
Pokemon()
Pokemon(String name, String pokeSpecies, PokemonType pokeType, int pokeValue, int maxHealth,
int baseAttackValue, int baseDefenseValue)
+displayPokemon(): void
+abstract attack(Pokemon p):int
+abstract defend(Pokemon p): int
+toSQL(): void We want to modify this class so that once
a Pokemon is created it can be added to
the database
Persistent Pokemon Storage
Persistent Pokemon Storage
• It is much better to just store the Pokémon at instantiation.
battlePokemon Method/Combat Class
We would ideally like to modify this
method to have it update the
database after the combat has
concluded.
pokemon_record
pokemon_battles
battlePokemon Method/Combat Class
Static variable
battlePokemon Method/Combat Class
battlePokemon Method/Combat Class