final tidy of lab02

This commit is contained in:
SowinskiBraeden committed 2025-09-22 13:57:43 -07:00
1 parent 93351ea56f
commit 95139d77e5
10 files changed
+76 -10

No files matched your search

+7 -1
View File
@@ -6,9 +6,15 @@
<component name="ChangeListManager">
<list default="true" id="4481728b-524b-48ee-9d70-e414a15f05bd" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Creature.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Creature.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/DamageException.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/DamageException.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Dragon.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Dragon.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Elf.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Elf.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/HealingException.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/HealingException.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/LowFirePowerException.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/LowFirePowerException.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/LowManaException.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/LowManaException.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/LowRageException.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/LowRageException.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Orc.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Orc.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -113,7 +119,7 @@
<workItem from="1758413771974" duration="332000" />
<workItem from="1758425336799" duration="21000" />
<workItem from="1758473282464" duration="4563000" />
<workItem from="1758570032207" duration="1691000" />
<workItem from="1758570032207" duration="2682000" />
</task>
<servers />
</component>
@@ -4,10 +4,13 @@ package ca.bcit.comp2522.lab02;
* Creature contains simple information regarding
* a creature such as its health, name and date of birth.
*
* @author Braeden Sowinski, Nicolas Agostini, Trishaan Shetty
* @author Braeden Sowinski
* @author Nicolas Agostini
* @author Trishaan Shetty
* @version 1.0.0
*/
public class Creature {
private static final int MIN_HEALTH = 1;
private static final int MAX_HEALTH = 100;
private static final int NO_HEALTH = 0;
@@ -68,10 +71,11 @@ public class Creature {
* @param dateOfBirth of creature
* @param health of creature to start
*/
public Creature(final String name,
public Creature(
final String name,
final Date dateOfBirth,
final int health)
{
final int health
) {
validateName(name);
validateDateOfBirth(dateOfBirth);
@@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02;
* for when a given damage value is invalid.
*
* @author Braeden Sowinski
* @author Nicolas Agostini
* @author Trishaan Shetty
* @version 1.0.0
*/
public class DamageException extends RuntimeException {
/**
* DamageException constructor
* @param message of DamageException error
*/
public DamageException(final String message) {
super(message);
}
+9 -3
View File
@@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab02;
* holds a firePower value.
*
* @author Braeden Sowinski
* @author Nicolas Agostini
* @author Trishaan Shetty
* @version 1.0.0
*/
public class Dragon extends Creature {
private static final int MAX_FIRE_POWER = 100;
private static final int MIN_FIRE_POWER = 0;
private static final int FIRE_POWER_USAGE = 10;
@@ -25,7 +28,6 @@ public class Dragon extends Creature {
private static void validateFirePower(final int firePower)
throws IllegalArgumentException
{
if (firePower < MIN_FIRE_POWER || firePower > MAX_FIRE_POWER) {
throw new IllegalArgumentException("Fire power is outside of valid range.");
}
@@ -60,7 +62,8 @@ public class Dragon extends Creature {
*/
@Override
public String getDetails() {
StringBuilder builder;
final StringBuilder builder;
builder = new StringBuilder();
@@ -84,7 +87,8 @@ public class Dragon extends Creature {
* @throws RuntimeException if the dragon is not alive to accomplish the action
*/
public void breatheFire(final Creature target)
throws LowFirePowerException, RuntimeException {
throws LowFirePowerException, RuntimeException
{
if (!this.isAlive()) {
throw new RuntimeException("The dragon is not alive.");
@@ -107,10 +111,12 @@ public class Dragon extends Creature {
* @param amount to increase firePower
*/
protected void restoreFirePower(final int amount) {
this.firePower += amount;
if (this.firePower > MAX_FIRE_POWER) {
this.firePower = MAX_FIRE_POWER;
}
}
}
+9 -1
View File
@@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab02;
* holds a mana value
*
* @author Braeden Sowinski
* @author Nicolas Agostini
* @author Trishaan Shetty
* @version 1.0.0
*/
public class Elf extends Creature {
private static final int MIN_MANA_VALUE = 0;
private static final int MAX_MANA_VALUE = 50;
private static final int MANA_DAMAGE = 10;
@@ -58,8 +61,11 @@ public class Elf extends Creature {
*/
@Override
public String getDetails() {
StringBuilder builder;
final StringBuilder builder;
builder = new StringBuilder();
builder.append("Is alive: " + this.isAlive());
builder.append(" Name: " + this.getName());
builder.append(" Date of birth: " + (this.getDateOfBirth()).getYyyyMmDd());
@@ -102,10 +108,12 @@ public class Elf extends Creature {
* @param amount to increase mana
*/
protected void restoreMana(final int amount) {
this.mana += amount;
if (this.mana > MAX_MANA_VALUE) {
this.mana = MAX_MANA_VALUE;
}
}
}
@@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02;
* for when a given healing value is invalid.
*
* @author Braeden Sowinski
* @author Nicolas Agostini
* @author Trishaan Shetty
* @version 1.0.0
*/
public class HealingException extends RuntimeException {
/**
* HealingException constructor
* @param message HealingException error message
*/
public HealingException(final String message) {
super(message);
}
@@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02;
* when firePower is too low to deal damage.
*
* @author Braeden Sowinski
* @author Nicolas Agostini
* @author Trishaan Shetty
* @version 1.0.0
*/
public class LowFirePowerException extends Exception {
/**
* LowFirePowerException constructor
* @param message LowFirePowerException error message
*/
public LowFirePowerException(final String message) {
super(message);
}
@@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02;
* when mana is too low to deal damage.
*
* @author Braeden Sowinski
* @author Nicolas Agostini
* @author Trishaan Shetty
* @version 1.0.0
*/
public class LowManaException extends Exception {
/**
* LowManaException constructor
* @param message LowManaException error message
*/
public LowManaException(final String message) {
super(message);
}
@@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02;
* when rage is too low to deal damage.
*
* @author Braeden Sowinski
* @author Nicolas Agostini
* @author Trishaan Shetty
* @version 1.0.0
*/
public class LowRageException extends Exception {
/**
* LowRageException constructor
* @param message LowRageException error message
*/
public LowRageException(final String message) {
super(message);
}
+8 -1
View File
@@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab02;
* holds a rage value. Orcs need anger management.
*
* @author Braeden Sowinski
* @author Nicolas Agostini
* @author Trishaan Shetty
* @version 1.0.0
*/
public class Orc extends Creature {
private static final int MIN_RAGE_VALUE = 0;
private static final int MAX_RAGE_VALUE = 30;
private static final int RAGE_INCREMENT = 5;
@@ -60,8 +63,11 @@ public class Orc extends Creature {
*/
@Override
public String getDetails() {
StringBuilder builder;
final StringBuilder builder;
builder = new StringBuilder();
builder.append("Is alive: " + this.isAlive());
builder.append(" Name: " + this.getName());
builder.append(" Date of birth: " + (this.getDateOfBirth()).getYyyyMmDd());
@@ -84,6 +90,7 @@ public class Orc extends Creature {
public void berserk(final Creature target)
throws LowRageException, RuntimeException
{
if(!this.isAlive()){
throw new RuntimeException("The orc is not alive.");
}