Results 1 to 8 of 8
Thread: <identifier> expected
- 12-03-2009, 04:00 AM #1
<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
- 12-03-2009, 04:36 AM #2
Member
- Join Date
- Aug 2009
- Posts
- 25
- Rep Power
- 0
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
-
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:
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 L4D { int health; class player { health = 300; } }
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 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 }
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 }
- 12-05-2009, 12:09 AM #4
i really dont know about super and this any explanation
Are you suggesting that Cocunuts migrate?!! -Monty Python
-
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!
- 12-05-2009, 03:47 AM #6
have you ever read any good books that you could suggest
Are you suggesting that Cocunuts migrate?!! -Monty Python
-
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.
- 12-05-2009, 05:05 AM #8
Similar Threads
-
Error:identifier expected(Help!)
By chhoton in forum New To JavaReplies: 8Last Post: 09-22-2009, 04:42 PM -
identifier expected
By tlouvierre in forum New To JavaReplies: 4Last Post: 05-28-2009, 12:11 AM -
getting identifier expected error . help me !
By victorkeath in forum New To JavaReplies: 3Last Post: 11-07-2008, 05:49 PM -
Identifier expected error
By vasu18 in forum New To JavaReplies: 1Last Post: 01-01-2008, 05:49 PM -
Error: <identifier> expected
By barney in forum AWT / SwingReplies: 2Last Post: 07-31-2007, 07:38 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks