Java Problem.

QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
edited March 2005 in Off-Topic
<div class="IPBDescription">Boolean no method?</div> Why does Java not recognize this is a method?(look for the battle system):

<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->import javax.swing.*;
class basepcnpc {
 int strength;
 int dexterity;
 int agility;
 int intelligence;
 int wisdom;
 int charisma;
 int maxhp;
 int maxmp;
 int hp=maxhp;
 int mp=maxmp;
 String name;
 String weaponname;
 int weapondamage;
 boolean learnedimpFireBall;
 boolean alreadylearned;
 
 int slashAttack(){
  int a = strength + (agility/2) + weapondamage;
  return a;
 }
 
 int useLightning(){
  int l = intelligence + (charisma/2);
  mp=mp-20;
  return l;
 }
 
 int useHeal(){
  int h = wisdom + (charisma/2);
  mp=mp-30;
  int overheal = 0;
  for(; overheal<=h||hp<=maxhp; overheal++){
   hp = hp+1;
  }
  return overheal;
 }
 
 boolean learnimpMove() {
  boolean learned;
  if(charisma > 18){
   System.out.println("You learned the imp's move!");
   return true;
   }
  else return false;
 }
 
 int LearnedimpFireBall(){
  int fb = 0;
  if(learnedimpFireBall=true){
   fb = charisma + (intelligence/2);
  }
  if(fb==0){
  System.out.println("You didn't learn the imp's move yet!");
  }
  return fb;
 }

int useRanged() {
 int r = dexterity + (agility/2) + weapondamage;
 return r;
}
 
 int impFireBall(){
  int f = intelligence + wisdom;
  return f;
 }
 
 basepcnpc() {
 }

 

basepcnpc(int s, int d, int a, int i, int w, int c, int h, int m, String n){
 strength=s;
 dexterity=d;
 agility=a;
 intelligence=i;
 wisdom=w;
 charisma=c;
 maxhp=h;
 maxmp=m;
 hp=maxhp;
 mp=maxmp;
 name=n;
}


}

class weapon {
    int strength;
    int dexterity;
    int agility;
    int intelligence;
    int wisdom;
    int charisma;
    int maxhp;
    int maxmp;
    int hp;
    int mp;
  int weapondamage;
  String weaponattribute;
 
}

/*class pcnpc {
String combatant1 = "player";
int str, dex, agi, Int, wis, cha, xhp, xmp, chp, cmp;
int getStr() {
int a = str;
return a;
}
}*/

class rpg {
public static void main(String args[]) throws java.lang.NoSuchMethodError{


basepcnpc first = new basepcnpc();
basepcnpc second = new basepcnpc();
/*The Battle System*/
 
 boolean battle(first.name,second.name.name){ {
 for(;first.name.hp>0&second.name.hp>0;) {
  String Battlechoice = "3";
  first.name.alreadylearned=false;
  if(first.name.alreadylearned=false)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4. Learn \n5.Attack from Far");
  if(first.name.alreadylearned=true)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4.Use \n5. Attack from Far");
  int battlechoice;
  battlechoice = Integer.parseInt(Battlechoice);
  if(battlechoice==1){
   second.name.hp = second.name.hp - first.slashAttack();
   System.out.println("imp's HP: "+second.name.hp+"/"+second.name.maxhp);
   first.name.hp = first.name.hp-second.name.slashAttack();
   System.out.println("first.name's HP: "+first.name.hp+"/"+first.name.maxhp);
   }
  if(battlechoice==2){
   second.name.hp = second.name.hp - first.name.useLightning();
   first.name.hp = first.name.hp-second.name.slashAttack();
   }
  if(battlechoice==3){
   first.name.hp = first.name.useHeal();
   System.out.println("first.name's Healed HP: "+first.name.hp);
   first.name.hp = first.name.hp-second.name.slashAttack();
  };
  if(battlechoice==4){
   
   if(first.name.alreadylearned=false){
   if(first.name.learnedimpFireBall=false){
    System.out.println(first.name.learnimpMove());
    System.out.println("You didn't learn the imp's move!");
    }
   else {
    first.name.learnedimpFireBall = true;
    first.name.alreadylearned = true;
   }
   }
   if(first.name.alreadylearned=true){
    System.out.println("You used the imp's move!");
    second.name.hp= second.name.hp-first.name.LearnedimpFireBall();
    System.out.println("imp's HP: "+second.name.hp+"/"+second.name.maxhp);
   }
  }
 
  if(battlechoice==5){
   second.name.hp = second.name.hp-first.name.useRanged();
   first.name.hp = first.name.hp-second.name.slashAttack();
   first.name.weapondamage=0;
  }
  }
  if(second.name.hp<0)return true;
  else return false;
  }}
 
 
 /*End Battle System*/

/*sdaiwchmweapon sword = new weapon();
weapon axe = new weapon();
weapon club = new weapon();*/
basepcnpc player = new basepcnpc(15,15,15,15,15,15,15,15,"player");
basepcnpc imp = new basepcnpc(3,1,5,2,1,1,210,210,"imp");
imp.hp=imp.maxhp;
System.out.println(imp.hp);
imp.weaponname = "Claw";
imp.weapondamage=0;
player.alreadylearned=false;
System.out.println(imp.hp);

/*for(;player.name.length()>2;){
player.name = JOptionPane.showInputDialog("What is your character's name?");
if(player.name.length()<=2)System.out.println("DO IT RIGHT");
}*/

 // Character creation system.
 for(int choicepoints=10;choicepoints>0;choicepoints--){
  String Choices;
  int choices;
  try{
  Choices = JOptionPane.showInputDialog("Choose what to put your attribute points into?"+
  "\n 1. Strength : "+player.strength+
  "\n 2. Dexterity : "+player.dexterity+
  "\n 3. Agility : "+player.agility+
  "\n 4. Intelligence : "+player.intelligence+
  "\n 5. Wisdom : "+player.wisdom+
  "\n 6. Charisma : "+player.charisma+
  "\n Choose by number. You have "+choicepoints+" points left to put into attributes."+
  "\n Just remember to put at least a few points into everything, or you may find your character...limited.");
  choices = Integer.parseInt(Choices);
  if(choices==1)player.strength++;
  if(choices==2)player.dexterity++;
  if(choices==3)player.agility++;
  if(choices==4)player.intelligence++;
  if(choices==5)player.wisdom++;
  if(choices==6)player.charisma++;
  }
  catch(java.lang.NumberFormatException exc){
   System.out.println("You must choose a number!");
   choicepoints++;
  }
}
  player.weaponname = JOptionPane.showInputDialog("What kind of weapon do you use?\n 1. Sword \n 2. Club \n 3. Axe");
  if(player.weaponname=="1"){
   player.weaponname= "Sword";
   player.weapondamage=20;
   }
  if(player.weaponname=="2"){
   player.weaponname= "Club";
   player.weapondamage=10;
   }
  if(player.weaponname=="3"){
   player.weaponname = "Axe";
   player.weapondamage=30;
   }
 
player.hp=(player.strength*5)+20;
player.mp=(player.intelligence*5)+10;
player.maxhp=player.hp;
player.maxmp=player.mp;


 
System.out.println(player.name+"'s Character Sheet:");
System.out.println();
System.out.println("Health: "+player.hp);
System.out.println("Mana: "+player.mp);
System.out.println();
System.out.println("Strength: "+player.strength);
System.out.println("Dexterity: "+player.dexterity);
System.out.println("Agility: "+player.agility);
System.out.println("Intelligence: "+player.intelligence);
System.out.println("Wisdom: "+player.wisdom);
System.out.println("Charisma: "+player.charisma);

System.out.println("An imp spawns behind you!");
System.out.println("Player HP:"+player.hp+" "+imp.hp);
// slashAttack();useLightning();useHeal;learnimpMove;useRanged;
 /*for(;player.hp>0&imp.hp>0;){
  String Battlechoice = "3";
  player.alreadylearned=false;
  if(player.alreadylearned=false)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4. Learn \n5.Attack from Far");
  if(player.alreadylearned=true)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4.Use \n5. Attack from Far");
  int battlechoice;
  battlechoice = Integer.parseInt(Battlechoice);
  if(battlechoice==1){
   imp.hp = imp.hp - player.slashAttack();
   System.out.println("imp's HP: "+imp.hp+"/"+imp.maxhp);
   player.hp = player.hp-imp.slashAttack();
   System.out.println("Player's HP: "+player.hp+"/"+player.maxhp);
   }
  if(battlechoice==2){
   imp.hp = imp.hp - player.useLightning();
   player.hp = player.hp-imp.slashAttack();
   }
  if(battlechoice==3){
   player.hp = player.useHeal();
   System.out.println("Player's Healed HP: "+player.hp);
   player.hp = player.hp-imp.slashAttack();
  };
  if(battlechoice==4){
   
   if(player.alreadylearned=false){
   if(player.learnedimpFireBall=false){
    System.out.println(player.learnimpMove());
    System.out.println("You didn't learn the imp's move!");
    }
   else {
    player.learnedimpFireBall = true;
    player.alreadylearned = true;
   }
   }
   if(player.alreadylearned=true){
    System.out.println("You used the imp's move!");
    imp.hp= imp.hp-player.LearnedimpFireBall();
    System.out.println("imp's HP: "+imp.hp+"/"+imp.maxhp);
   }
  }
 
  if(battlechoice==5){
   imp.hp = imp.hp-player.useRanged();
   player.hp = player.hp-imp.slashAttack();
   player.weapondamage=0;
  }*/
 System.exit(0);
 }

}<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

Comments

  • SnidelySnidely Join Date: 2003-02-04 Member: 13098Members
    edited March 2005
    Just checking - you did mean to comment out that last bit, right? (Lines 261-306.)
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    Right. And for further clarification, the specific portion this is intended for is lines 123-179.

    <!--emo&:(--><img src='http://www.unknownworlds.com/forums/html/emoticons/sad-fix.gif' border='0' style='vertical-align:middle' alt='sad-fix.gif' /><!--endemo-->
  • SnidelySnidely Join Date: 2003-02-04 Member: 13098Members
    edited March 2005
  • 0blique0blique Join Date: 2003-05-18 Member: 16477Members
    First, can you be more specific as to the problem? Does it not compile, and if not, what does it say? Or, does it compile but not run, and if not, what is it supposed to be doing and what is it not doing.

    Also, why do you have

    boolean battle()
    {return false}

    inside your main function? Are you trying to define a function, or are you trying to decalre a variable?
  • SnidelySnidely Join Date: 2003-02-04 Member: 13098Members
    edited March 2005
    I just realised - it's quite simple. You need to have battle() outside the <i>public static void main(String args[]) throws java.lang.NoSuchMethodError{
    ....
    }</i> section. For example;

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->class rpg {

    public boolean battle()
    {return false;}

    public static void main(String args[]) throws java.lang.NoSuchMethodError{
    ...
    <!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    EDIT: oh, and the return false needed a semicolon. This sorts that particular problem...

    SECOND EDIT: The code function takes out tabs. That's a major pain in the butt.
  • TychoCelchuuuTychoCelchuuu Anememone Join Date: 2002-03-23 Member: 345Members
    Why do you capitalize "spawned" and "behind" in "The imp Spawned Behind you?" That's incorrect and the pure wrongness will spill out and break the code. That said I'd like to know what the exact problem is before trying to find you a solution.
  • SoulSkorpionSoulSkorpion Join Date: 2002-04-12 Member: 423Members
    <!--QuoteBegin-TychoCelchuuu+Mar 17 2005, 06:07 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (TychoCelchuuu @ Mar 17 2005, 06:07 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Why do you capitalize "spawned" and "behind" in "The imp Spawned Behind you?" That's incorrect and the pure wrongness will spill out and break the code. That said I'd like to know what the exact problem is before trying to find you a solution. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    *swat*
  • TequilaTequila Join Date: 2003-08-13 Member: 19660Members
    edited March 2005
    <!--QuoteBegin-SoulSkorpion+Mar 17 2005, 02:18 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (SoulSkorpion @ Mar 17 2005, 02:18 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--QuoteBegin-TychoCelchuuu+Mar 17 2005, 06:07 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (TychoCelchuuu @ Mar 17 2005, 06:07 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Why do you capitalize "spawned" and "behind" in "The imp Spawned Behind you?" That's incorrect and the pure wrongness will spill out and break the code. That said I'd like to know what the exact problem is before trying to find you a solution. <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    *swat* <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    Grammar is for life, not just for Christmas.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    Ah, I forgot to take out my hopeful(but still didn't work) tempfix on that method. As I said, it doesn't recognize the boolean as a method, like it should. Here's the exact error(yeah, I know. I explained it as much as it did.)

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->rpg.java:125: ';' expected
            boolean battle(first.name,second.name.name){ {<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    It motions for the semicolon to go after battle. Not battle(), but battle. As if I was just declaring it as a regular boolean: boolean battle;. Yeah. GAH.

    Check back to the battle system area, I've updated the code.
  • TranquilChaosTranquilChaos Join Date: 2003-07-25 Member: 18425Members
    edited March 2005
    Could it be battle(first.name,second.name.name) possibly?

    When defining a method that takes parameters you declare the parameters' class and the variable names they will be recognized by in the method.

    Ex: (battle takes two Character objects as parameters)
    public boolean battle(Character person1, Character person2)

    And then when you call battle you specify* the specific objects that it will take as parameters.

    Ex: (battle is called with the Character objects johnny and susie as parameters)
    battle(johnny, susie)

    Then the method (function) will run its course, referring to johnny as person1 and susie as person2.
  • SkulkBaitSkulkBait Join Date: 2003-02-11 Member: 13423Members
    edited March 2005
    <!--QuoteBegin-Quaunaut+Mar 17 2005, 10:35 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Quaunaut @ Mar 17 2005, 10:35 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->rpg.java:125: ';' expected
            boolean battle(first.name,second.name.name){ {<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    It motions for the semicolon to go after battle. Not battle(), but battle. As if I was just declaring it as a regular boolean: boolean battle;. Yeah. GAH.

    Check back to the battle system area, I've updated the code. <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    I'm pretty sure its still the same problem that 0blique and Snidely mentioned. You cannot declare a method from within annother method (unless I've forgotten too much java). In this case, you cannot declare battle() inside of main(). Therefore the compiler thinks that you are trying to declare a plain old boolean scalar variable. The solution is still the same: move the battle() method declaration outside of main().

    Edit: Also what TranquilChaos says. You seem to be confused between a method declaration and a method call.
  • ZelZel Join Date: 2003-01-27 Member: 12861Members
    theres also too many { right there.

    heres the little java program ive been working on for the last two days, run the driver.class and enter text into the command window
    <a href='ftp://guest:wordpass@yuo.ath.cx/Upload/Fractal.zip' target='_blank'>ftp://guest:wordpass@yuo.ath.cx/Upload/Fractal.zip</a>
  • panda_de_malheureuxpanda_de_malheureux Join Date: 2003-12-26 Member: 24775Members
    I hope you don't get confused with all those capital and lowercase variable names. As for the question: no idea.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    It may be that Snidely is correct.

    Its not the second.name.name. That was me typing randomly.

    I'm a very personal coder atm- plan to get more proffessional over time.

    Thanks for your help, folks.
Sign In or Register to comment.