Results 1 to 8 of 8
  1. #1
    SwEeTAcTioN's Avatar
    SwEeTAcTioN is offline Member
    Join Date
    Oct 2009
    Posts
    69
    Rep Power
    0

    Default <identifier> expected

    so im making a game with JOptionPanes and stuff like that but im having problems with some of the beggining

    keep on getting <identifier> expected errors:mad:

    can anyone explain why and help

    very much appreciated:)

    Java Code:
    import javax.swing.*;
    import java.util.Random;
    public class L4D{
    int level;
    int exp;
    int money;
    int health;
    class player
    {
     health=50;   //<identifier> expected error
     money=500; //<identifier> expected error
     level=1;       //<identifier> expected error
     exp=0;        //<identifier> expected error
    }
    class zombie
    {
     health=25;          //<identifier> expected error
     money=10||25;   //<identifier> expected error
     level=1;             //<identifier> expected error
     exp=50;             //<identifier> expected error
    }
    class superZombie
    {
     health=75;
     money=100||250;         // same as above
     level=5;
     exp=200;
    }
    class megaZombie
    {
     health=150;
     money=500||1000;        // same as above
     level=10;
     exp=500;
    }
    class ultraZombie
    {
     health=300;
     money=2000||4000;   //same as above
     level=25;
     exp=1500;
    }
    class bossZombie
    {
     health=500;
     money=5000||10000;  //same as above
     level=50;
     exp=5000;
    }
    class finalZombie
    {
     health=1000;
     money=10000||25000;  // same as above
     level=100;
     exp=10000;
    }
    /*public static void moneyUp(int one)    //start comment
     {
       int newmoney=money+one;
     }
     public static void levelUp(int one)
     {
     	int newLevel=level+one;
     }
     public static void expUp(int one)
     {
     	int newExp=exp+one;
     }
    public static void healthUp(int one)
     {
     	int newHealth=health+one;
     }
    */                                                   //end comment
    }
    Last edited by SwEeTAcTioN; 12-03-2009 at 04:06 AM.
    Are you suggesting that Cocunuts migrate?!! -Monty Python

  2. #2
    steelshark is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

    Default

    if i may give you a piece of advice, i would create a class zombi, that you give some attributes like health etc...
    and i would make superzombie , megazombi subclasses of that main class..Just a piece of advice , polymorphism and overloading will ease up your code

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You've got a class called L4D, and then for lord-knows what reason you fill it with a bunch of inner classes that are trying to magically pretend that they have L4D fields, and this isn't going to work. For example let's look at some minimal code:
    Java Code:
    public class L4D {
       int health;
    
       class player {
          health = 300;
       }
    }
    This player class doesn't have a health field as that's a field of L4D, period. I'm not sure what you're trying to do, but I'd do something like so:
    Java Code:
    public class Player {
       int level;
       int exp;
       int money;
       int health;
       
       public Player(int level, int exp, int money, int health) {
          this.level = level;
          this.exp = exp;
          this.money = money;
          this.health = health;
       }
       
       // setters and getters 
    }
    and then say have a Zombie class that extends this and has an extra field or whatever distinguishes a Zombie from a player:
    Java Code:
    public class Zombie extends Player {
       int zombiness;
       
       public Zombie(int level, int exp, int money, int health, int zombiness) {
          super(level, exp, money, health);
          this.zombiness = zombiness;
       }
       
       // setters and getters
    }

  4. #4
    SwEeTAcTioN's Avatar
    SwEeTAcTioN is offline Member
    Join Date
    Oct 2009
    Posts
    69
    Rep Power
    0

    Default

    i really dont know about super and this any explanation
    Are you suggesting that Cocunuts migrate?!! -Monty Python

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by SwEeTAcTioN View Post
    i really dont know about super and this any explanation
    Hm, this would be a tall order to explain inheritance and OOPs within the confines of a forum. If you have a decent textbook on Java and OOPs programming, I suggest you study the chapters on inheritance. I believe that they will be eye-opening for you, and once you read them, this all will become obvious. If you don't have a decent textbook, it'd be a worthwhile investment.

    Much luck!

  6. #6
    SwEeTAcTioN's Avatar
    SwEeTAcTioN is offline Member
    Join Date
    Oct 2009
    Posts
    69
    Rep Power
    0

    Default

    have you ever read any good books that you could suggest
    Are you suggesting that Cocunuts migrate?!! -Monty Python

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Head First Java might be a good place to start. Myself, I bought a couple of used books when I was trying to first learn Java.

  8. #8
    SwEeTAcTioN's Avatar
    SwEeTAcTioN is offline Member
    Join Date
    Oct 2009
    Posts
    69
    Rep Power
    0

    Default

    Thanks ill take a look:)
    Are you suggesting that Cocunuts migrate?!! -Monty Python

Similar Threads

  1. Error:identifier expected(Help!)
    By chhoton in forum New To Java
    Replies: 8
    Last Post: 09-22-2009, 04:42 PM
  2. identifier expected
    By tlouvierre in forum New To Java
    Replies: 4
    Last Post: 05-28-2009, 12:11 AM
  3. getting identifier expected error . help me !
    By victorkeath in forum New To Java
    Replies: 3
    Last Post: 11-07-2008, 05:49 PM
  4. Identifier expected error
    By vasu18 in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 05:49 PM
  5. Error: <identifier> expected
    By barney in forum AWT / Swing
    Replies: 2
    Last Post: 07-31-2007, 07:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •