I'm writing a program called Curse Detector. The idea is that you answer 5 questions and this program tells you if an item is cursed.
The item is cursed if:
1) The item adds +6 or less to the player's AC bonus AND is worth less than 250,000 gold pieces AND either provides Energy Immunity or Weapon Breaking
2) Adds more than +6 to AC and does not provide Energy Immunity
3) Summons Monsters
I am using two classes, and interface, and CinReader.
My problem is that: no matter what I put into the test, it tells me that the item is cursed, even if it shouldn't be.
Here's the interface:
public interface CurseDetector { /** * Welcome to the Curse Detector program. This program will help you determine if your magical items are cursed * * @param addsLessThan7 true if greater than 6. * @param worthOver250K true if worth more than 250,000 gold peices * @param energyImmunity true if it provides energy immunity * @param weaponBreaking true if it provides weapons breaking * @param summonsMonsters true if it provides monster summoning * * @return true if likely cursed, false if likely not cursed */ public boolean detectCurse(boolean addsLessThan7, boolean worthOver250K, boolean energyImmunity, boolean weaponBreaking, boolean summonsMonsters ); }
Here's the AberrationsDetector:
/** * Write a description of class AberrationsDetector here. * * @author Erik Ingvoldsen * @version 1.0 */ public class AberrationsDetector implements CurseDetector { boolean returnBoolean=false; public boolean detectCurse(boolean addsLessThan7, boolean worthOver250K,boolean energyImmunity, boolean weaponBreaking, boolean summonsMonsters) { if(summonsMonsters=true){ returnBoolean=true; }else{ if(summonsMonsters=false){ if(addsLessThan7==true){ if(worthOver250K==false){ if(energyImmunity==true){ returnBoolean=true; } else if(weaponBreaking==true){ returnBoolean=true; } else if(energyImmunity||weaponBreaking==true){ returnBoolean=false; } } }else{ if(addsLessThan7==false){ if(energyImmunity=false){ returnBoolean=true; } } } }else{ returnBoolean=false; } } return returnBoolean; } }
And here is the test:
/** * A tool designed to use the Curse Detector * * @author Erik Ingvoldsen * @version 1.0 */ public class CurseTest { static CinReader Cin= new CinReader(); public CurseTest() { System.out.println("Welcome to the Curse Detector program."); System.out.println("his program will help you determine if your magical items are cursed."); System.out.println("Here are a few questions for you:"); System.out.println(" "); Question1(); } public static void Question1(){ System.out.println("What AC advantage does the magic item provide? (Enter an integer)"); int Q1=Cin.readInt(); if(Q1>6){ boolean addsLessThan7=true; }else{ boolean addsLessThan7=false; } Question2(); } public static void Question2(){ System.out.println(" "); System.out.println("How much is the magic item worth? (Enter an integer)"); int Q2=Cin.readInt(); if(Q2>250000){ boolean worthOver250K=true; }else{ boolean worthOver250K=false; } Question3(); } public static void Question3(){ System.out.println(" "); System.out.println("Does the item provide Energy Immunity? (Yes or No)"); String Q3=Cin.readString(); if(Q3.equals("yes")){ boolean energyImmunity=true; }else if(Q3.equals("no")){ boolean energyImmunity=false; }else{ System.out.println("Not a valid answer. Do not use any capital letters."); Question3(); } Question4(); } public static void Question4(){ System.out.println(" "); System.out.println("Does the item provide Weapon Breaking? (Yes or No)"); String Q4=Cin.readString(); if(Q4.equals("yes")){ boolean weaponBreaking=true; }else if(Q4.equals("no")){ boolean weaponBreaking=false; }else{ System.out.println("Not a valid answer. Do not use any capital letters."); Question4(); } Question5(); } public static void Question5(){ System.out.println(" "); System.out.println("Does the item Summon Monsters? (Yes or No)"); String Q5=Cin.readString(); if(Q5.equals("yes")){ boolean summonsMonsters=true; }else if(Q5.equals("no")){ boolean summonsMonsters=false; }else{ System.out.println("Not a valid answer. Do not use any capital letters."); Question5(); } Answer(); } public static void Answer(){ AberrationsDetector myDetector= new AberrationsDetector(); myDetector.detectCurse(false, false, false, false, false); System.out.println(" "); if(myDetector.detectCurse(false, false, false, false, false)==true){ System.out.println("This time is cursed!"); }else{ System.out.println("This item is not cursed."); } } }