I’m new to Java and I’m trying to make an lvling system. Hers my code so far:
import java.util.*;
class Player
{
private String Name;
private int Level;
private int EXP;
int NextGoaltoLvl = 1000;
public Player(String n, int lvl, int xp)
{
Name = n;
Level = lvl;
EXP = xp;
}
public void printStats()
{
System.out.println("Name: " +Name);
System.out.println("Level: " +Level);
System.out.println("Exp: " + EXP);
}
public void addLevel(int addlvl)
{
Level += addlvl;
System.out.println("Congratulations,"+ Name +",you have leveled up to " + Level + "!");
}
public void addExp(int num)
{
EXP += num;
if (EXP == NextGoaltoLvl)
{
addLevel(1); NextGoaltoLvl += 1000; EXP = 0;
}
}
}
public class MainC
{
public static void main(String[] args)
{
Player Player01 = new Player("kert109",1,0);
for (int i = 0; i >= 10000; i++)
{
Player01.addExp(1);
}
Player01.printStats();
}
}
Player01.printStats();
I still having an error here. Says: Syntax error, insert “}” to complete ClassBody.
I have no idea whats wrong. Help? I have check ever “{” and “}”. I have cleaned to code too. (Using Eclipse.)
Instead of
(an infinite loop? outside all function code? compile error + logic error)
I think you want
(increment level if XP reaches new level XP)
A. R. S points out another serious issue with your for loop.
Instead of
You want
or just
If what you want to do is to add 10000 XP to the player