I'm making a Weapons Class and a Weapons Test.
The Weapons Class gives me the damage power of each weapon (which changes each time) and the Weapons Test is supposed to show me the value and tell me which weapon "wins" based on score. If it's a tie, then it says "It's a Tie!" My weapons are Shortspear, Throwing Axe, and Flail.
If the Shortspear wins, it will always say the Shortspear wins.
But if the Throwing Axe wins, it will only state the Throwing Axe wins IF the Shortspear has a higher number than the Flail or if the Shortspear and Flail tie. If the Flail is a higher number than the Shortspear, it will not say anything, even when the Throwing Axe has the highest number.
For example:
Which weapon is the strongest?
Shortspear: 3
Throwing Axe: 6
Flail: 2
Throwing Axe wins!
^ This is fine.
Which weapon is the strongest?
Shortspear: 2
Throwing Axe: 5
Flail: 4
^ This is all the test shows. It doesn't acknowledge the Axe's victory.
The same thing happens to the Flail, but only when the Shortspear has a higher number than the Throwing Axe. If they are tied or the Throwing Axe has a higher number, then it acknowledges the Flail's victory.
This is my code for the Weapon Class:
/** * A weapon class * * @author Erik * @version 1 */ import java.util.Random; public class Weapon { //fields String name; String size; String cat; String type; String description; public int cost; public int maxDamage; public int critMult; public int range; //initialize public Weapon(String name, String size, String cat, String type, String description, int cost, int maxDamage, int critMult, int range) { this.name=name; this.size=size; this.cat=cat; this.type=type; this.description=description; this.cost=cost; this.maxDamage=maxDamage; this.critMult=critMult; this.range=range; } public int getDamage(){ int total=0; Random rand= new Random (); total+=rand.nextInt(maxDamage)+1; return total; } public int getCriticalDamage(){ int total=0; Random rand= new Random (); total+=(rand.nextInt(maxDamage)*critMult)+1; return total; } //methods }
This is my code for the Weapon Test:
/** * A test for the weapon class * * @author Erik * @version 1 */ public class WeaponTest { static int SpearDamage; static int FlailDamage; static int AxeDamage; public static void main(String[] args) { Weapon myShortspear = new Weapon( "Shortspear", "Long", "Spear", "P", "A spear with narrow range that deals heavy damage. Easily blocked with shields.", 1, 6, 2, 20); Weapon myThrowingAxe = new Weapon( "Throwing Axe", "Short", "Axe", "S", "A powerful ranged weapon with short distance.", 8, 6, 2, 10); Weapon myFlail = new Weapon( "Flail", "Medium", "Flail", "B", "An unpredictable weapon that's hard to master.", 8, 6, 2, 5); System.out.println("Shortspear: A spear with narrow range that deals heavy damage. Easily blocked with shields."); System.out.println("Throwing Axe: A powerful ranged weapon with short distance."); System.out.println("Flail: An unpredictable weapon that's hard to master."); System.out.println(" "); System.out.println("Which weapon is the strongest?"); SpearDamage=myShortspear.getDamage(); AxeDamage=myThrowingAxe.getDamage(); FlailDamage=myFlail.getDamage(); System.out.println("Shortspear: " + SpearDamage); System.out.println("Throwing Axe: " + AxeDamage); System.out.println("Flail: " + FlailDamage); System.out.println(" "); if(SpearDamage>AxeDamage){ if(SpearDamage>FlailDamage){ System.out.println("Shortspear wins!"); } else if(SpearDamage==FlailDamage){ System.out.println("It's a tie!"); } }else{ if(FlailDamage>SpearDamage){ if(FlailDamage>AxeDamage){ System.out.println("Flail wins!"); } else if(FlailDamage==AxeDamage){ System.out.println("It's a tie!"); } }else{ if(AxeDamage>SpearDamage){ if(AxeDamage>FlailDamage){ System.out.println("Throwing Axe wins!"); } else if(AxeDamage==FlailDamage){ System.out.println("It's a tie!"); } } } } } }
Can anyone see the issue?