I'm getting the following error:
C:\\Users\\[USER]\\Desktop\\Java\\TextAdventure\\TextAdventure.java:39: cannot find symbol
symbol : method damage(int)
location: class TextAdventure
out.println("you do "+damage(pS)+" damage");
public class TextAdventure{
public static int pS=0;
public static void main(String args[]){
Scanner reader=new Scanner(in);
while((pS>10) || (pS<1)){
out.println("\nEnter your strength attribute: ");
pS=reader.nextInt();
}//ask for strength, repeat if not between 1 and 10
out.println("you do "+damage(pS)+" damage");
The RandomDamage
class with the damage(int)
method is as follows:
public class RandomDamage {
public static int damage(int x){
int dMult=(int)(Math.random()*11);
return dMult*x;
}
}
I'm using JCreator LE's "project" thing for the first time, so I'm just assuming that I don't need to deal with creating different packages or anything. I have RandomDamage
and TextAdventure
under "Package Default"
You have to specify the class.
out.println("you do "+ RandomDamage.damage(pS)+" damage");
If you don't, it will look for a method damage(int)
inside your current class, TextAdventure
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.