lab02 src code, no tests or main

This commit is contained in:
SowinskiBraeden committed 2025-09-17 19:47:26 -07:00
1 parent fe8be748ca
commit 18b7c28e65
11 files changed
+360 -42

No files matched your search

+41 -30
View File
@@ -5,23 +5,26 @@
</component>
<component name="ChangeListManager">
<list default="true" id="4481728b-524b-48ee-9d70-e414a15f05bd" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/comp2522.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab01/BankAccount.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab01/BankClient.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab01/Date.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab01/Main.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab01/Name.java" afterDir="false" />
<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/Date.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Date.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/HealingException.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/HealingException.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Exception" />
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
@@ -36,26 +39,31 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ModuleVcsDetector.initialDetectionPerformed": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "main",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "/home/flami/Projects/comp2522",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"project.structure.last.edited": "Project",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2",
"settings.editor.selected.configurable": "preferences.lookFeel",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/flami/Projects/comp2522&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;project.structure.last.edited&quot;: &quot;Project&quot;,
&quot;project.structure.proportion&quot;: &quot;0.15&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="ca.bcit.comp2522.lab02" />
</key>
</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
@@ -75,6 +83,9 @@
<workItem from="1757978555342" duration="50000" />
<workItem from="1757978628819" duration="106000" />
<workItem from="1757978741081" duration="333000" />
<workItem from="1757986074841" duration="318000" />
<workItem from="1758045661655" duration="660000" />
<workItem from="1758156443615" duration="6374000" />
</task>
<servers />
</component>
+22 -2
View File
@@ -138,11 +138,31 @@ public class Creature {
}
}
/**
* getAgeYears calculates the age years
* from Date.MAX_YEAR which is current year
*
* @return age in years
*/
protected int getAgeYears() {
return 0;
return Date.MAX_YEAR - this.dateOfBirth.getYear();
}
/**
* getDetails of the creature
*
* @return details of the creature.
*/
protected String getDetails() {
return "";
return "Name: " + this.name;
}
/**
* getName of creature
*
* @return name of the creature
*/
protected String getName() {
return this.name;
}
}
@@ -1,5 +1,12 @@
package ca.bcit.comp2522.lab02;
/**
* DamageException is an unchecked exception
* for when a given damage value is invalid.
*
* @author Braeden Sowinski
* @version 1.0.0
*/
public class DamageException extends RuntimeException {
public DamageException(String message) {
super(message);
+2 -1
View File
@@ -10,9 +10,10 @@ package ca.bcit.comp2522.lab02;
* @version 1.0.0
*/
public final class Date {
public static final int MAX_YEAR = 2025;
// Domain of dates
private static final int MIN_YEAR = 1800;
private static final int MAX_YEAR = 2025;
private static final int MIN_DAY = 1;
private static final int CURRENT_DAY = 15;
private static final int CURRENT_MONTH = 9;
+52 -9
View File
@@ -10,12 +10,17 @@ package ca.bcit.comp2522.lab02;
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;
private static final int FIRE_POWER_DAMAGE = 20;
private final int firePower;
private int firePower;
/*
validateFirePower ensures input firepower is in valid
range of MAX_FIRE_POWER and MIN_FIRE_POWER.
/**
* validateFirePower ensures a given value is within
* the correct firePower range
*
* @param firePower to verify
* @throws IllegalArgumentException if firePower is outside valid range
*/
private static void validateFirePower(int firePower)
throws IllegalArgumentException {
@@ -34,18 +39,56 @@ public class Dragon extends Creature {
* @param firePower int
*/
Dragon(
final String name,
final Date dateOfBirth,
final int health,
final int firePower
final String name,
final Date dateOfBirth,
final int health,
final int firePower
) {
super(name, dateOfBirth, health);
this.firePower = firePower;
}
/**
* getDetails of Dragon with firepower
*
* @return details of dragon
*/
@Override
protected String getDetails() {
return "a";
return "Name: " + this.getName() + " FirePower: " + this.firePower;
}
/**
* breathFire onto Creatures to deal damage
* and reduces current firePower value
*
* @param target Creature to deal damage to
* @throws LowFirePowerException if not enough firePower
*/
protected void breatheFire(final Creature target)
throws LowFirePowerException
{
if (firePower > FIRE_POWER_USAGE) {
throw new LowFirePowerException("Fire power too low");
}
this.firePower -= FIRE_POWER_USAGE;
target.takeDamage(FIRE_POWER_DAMAGE);
}
/**
* restoreFirePower by a given value and is
* maxed by MAX_FIRE_POWER
*
* @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;
}
}
}
+96
View File
@@ -0,0 +1,96 @@
package ca.bcit.comp2522.lab02;
/**
* Elf extends Creature and
* holds a mana value? Never heard of that
*
* @author Braeden Sowinski
* @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;
private static final int MANA_USAGE = 5;
private int mana;
/*
* validateManaValue ensures a given value is within
* the correct mana range
*
* @param value to verify
* @throws IllegalArgumentException if mana is outside valid range
*/
private static void validateManaValue(final int value)
throws IllegalArgumentException
{
if (value < MIN_MANA_VALUE || value > MAX_MANA_VALUE) {
throw new IllegalArgumentException("Invalid mana value: " + value);
}
}
/**
* Elf constructor
*
* @param name String
* @param dateOfBirth Date
* @param health int
* @param mana int
*/
Elf(
final String name,
final Date dateOfBirth,
final int health,
final int mana
) {
super(name, dateOfBirth, health);
validateManaValue(mana);
this.mana = mana;
}
/**
* getDetails of elf with Mana
*
* @return details of elf
*/
@Override
protected String getDetails() {
return "Name: " + this.getName() + " Mana: " + this.mana;
}
/**
* castSpell onto target Creatures to deal damage
* and reduces current mana value
*
* @param target Creature to deal damage to
* @throws LowManaException if mana value is too low
*/
protected void castSpell(final Creature target)
throws LowManaException
{
if (this.mana < MANA_USAGE) {
throw new LowManaException("Not enough mana to cast spell");
}
this.mana -= MANA_USAGE;
target.takeDamage(MANA_DAMAGE);
}
/**
* restoreMana by a given value and is maxed
* to MAX_MANA_VALUE
*
* @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;
}
}
}
@@ -1,5 +1,12 @@
package ca.bcit.comp2522.lab02;
/**
* HealingException is an unchecked exception
* for when a given healing value is invalid.
*
* @author Braeden Sowinski
* @version 1.0.0
*/
public class HealingException extends RuntimeException {
public HealingException(String message) {
super(message);
@@ -0,0 +1,14 @@
package ca.bcit.comp2522.lab02;
/**
* LowFirePowerException is a checked exception
* when firePower is too low to deal damage.
*
* @author Braeden Sowinski
* @version 1.0.0
*/
public class LowFirePowerException extends Exception {
public LowFirePowerException(final String message) {
super(message);
}
}
@@ -0,0 +1,14 @@
package ca.bcit.comp2522.lab02;
/**
* LowManaException is a checked exception
* when mana is too low to deal damage.
*
* @author Braeden Sowinski
* @version 1.0.0
*/
public class LowManaException extends Exception {
public LowManaException(final String message) {
super(message);
}
}
@@ -0,0 +1,14 @@
package ca.bcit.comp2522.lab02;
/**
* LowRageException is a checked exception
* when rage is too low to deal damage.
*
* @author Braeden Sowinski
* @version 1.0.0
*/
public class LowRageException extends Exception {
public LowRageException(final String message) {
super(message);
}
}
+91
View File
@@ -0,0 +1,91 @@
package ca.bcit.comp2522.lab02;
/**
* Orc extends Creature and
* holds a rage value. Orcs need anger management.
*
* @author Braeden Sowinski
* @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;
private static final int DAMAGE_THRESHOLD = 20;
private static final int DAMAGE = 15;
private static final int DOUBLE = 2;
private int rage;
/*
* validateRageValue ensures a given value is within
* the correct rage range
*
* @param value to verify
* @throws IllegalArgumentException if rage is outside valid range
*/
private static void validateRageValue(final int value)
throws IllegalArgumentException
{
if (value < MIN_RAGE_VALUE || value > MAX_RAGE_VALUE) {
throw new IllegalArgumentException("Invalid rage value: " + value);
}
}
/**
* Orc constructor
*
* @param name String
* @param dateOfBirth Date
* @param health int
* @param rage int
*/
Orc(
final String name,
final Date dateOfBirth,
final int health,
final int rage
) {
super(name, dateOfBirth, health);
validateRageValue(rage);
this.rage = rage;
}
/**
* getDetails of orc with rage
*
* @return details of orc
*/
@Override
protected String getDetails() {
return "Name: " + this.getName() + " Rage: " + this.rage;
}
/**
* bezerk goes the orc when he is really mad.
* dealing damage to target Creatures with the
* potential for double damage.
*
* @param target Creature to deal damage to
* @throws LowRageException if rage value is too low
*/
protected void bezerk(final Creature target)
throws LowRageException
{
this.rage += RAGE_INCREMENT;
if (this.rage > MAX_RAGE_VALUE) {
this.rage = MAX_RAGE_VALUE;
}
if (rage < RAGE_INCREMENT) {
throw new LowRageException("Rage too low");
} else if (this.rage > DAMAGE_THRESHOLD) {
target.takeDamage(DAMAGE * DOUBLE);
} else {
target.takeDamage(DOUBLE);
}
}
}