java - Cannot find symbol with mutators and accessors -
i'm pretty knew java don't quite understand i'm looking when i'm trying find errors in program. i'm trying create player class game , i'm getting "cannot find symbol" error. did research prior asking question don't understand responses.
i errors such as:
playerclass.java:51: cannot find symbol symbol : variable getlevel location: class playerclass playerclass.setlevel(playerclass.getlevel + 1); ^ playerclass.java:51: setlevel(int) in playerclass cannot applied (<nulltype>) playerclass.setlevel(playerclass.getlevel + 1); ^ playerclass.java:93: cannot find symbol symbol : variable getname location: class playerclass if (name.equals(playerclass.getname)) ^ 3 errors
but here's class:
import io.*; //class: player public class playerclass { //class fields: name, level, damage, health, kills //constructors: private static int level, health, kills, damage; private static string name; //default constructor: import: none public playerclass() { name = "jeremy"; level = 1; health = 100; kills = 0; } //alternate constructor: import: inname public playerclass(string inname) { name = inname; level = 1; health = 100; kills = 0; } //copy constructor: import: inplayer public playerclass(playerclass inplayer) { name = inplayer.getname(); } //mutators: //setname import: inname public void setname(playerclass inplayer) { name = inplayer.getname(); } //setlevel import: inlevel public int setlevel(int inlevel) { playerclass.level = inlevel; } //levelup import:inplayer public int levelup(playerclass inplayer) { playerclass.setlevel(playerclass.getlevel + 1); } //accessors: //getname import: none export: name public string getname() { return name; } //getlevel import: none export: level public int getlevel() { return level; } //gethealth import: none export: health public int gethealth() { return health; } //getkills import: none export: kills public int getkills() { return kills; } //tostring import: none export: playerstr public string tostring() { string playerstr; playerstr = "name: " + name + "level: " + level + "kills: " + kills; return playerstr; } //equals import: inplayer export: same public boolean equals() { boolean same; same = false; if (name.equals(playerclass.getname)) { same = true; } return same; } }
u have missed parenthesis on getlevel() , getname() , have in mind have static fields. also, have put
//setlevel import: inlevel public int setlevel(int inlevel) { playerclass.level = inlevel; }
where should void
instead of int
if want setter, levelup()
method.
Comments
Post a Comment