Java 变量没有相应地更新

Java 变量没有相应地更新,java,Java,当我尝试接受用户输入并更新“Dexterity”变量时,它只反映在下面几行代码中。当我再次尝试运行同一命令时,它不会反映以前的输入。由于某些原因,它没有相应地更新变量 public class SetAttributes { public String userInput; double Dexterity; double Strength; double Intelligence; double Stamina; double SkillPoi

当我尝试接受用户输入并更新“Dexterity”变量时,它只反映在下面几行代码中。当我再次尝试运行同一命令时,它不会反映以前的输入。由于某些原因,它没有相应地更新变量

public class SetAttributes {

    public String userInput;
    double Dexterity;
    double Strength;
    double Intelligence;
    double Stamina;
    double SkillPoints = 50;



    public SetAttributes() {
        this.SetDex(0);
        this.SetStr(0);
        this.SetInt(0);
        this.SetSta(0);
        this.SetSkillPoints(50);
    }

    public double GetSP(){
        return SkillPoints;

    }
    public double GetDex() {
        return Dexterity;
    }
    public void SetDex(double dexterity) {
        this.Dexterity = dexterity;
    }

    public double GetStr(){
        return Strength;
    }

    public double GetInt(){
        return Intelligence;
    }

    public double GetSta(){
        return Stamina;
    }





    public void SetStr(double strength){
        this.Strength = strength;
    }
    public void SetInt(double intelligence){
        this.Intelligence = intelligence;
    }
    public void SetSta(double stamina){
        this.Stamina = stamina;
    }
    public void SetSkillPoints(double skillPoints) {this.SkillPoints = skillPoints;};
}



每次调用静态方法“spend”时,您都在创建一个新的SetAttributes实例,然后您就阻塞了用户输入。但在创建新实例的块之前,新实例的所有属性都设置为0

这发生在零参数构造函数中,就在这里:

public SetAttributes() {
        this.SetDex(0);
        this.SetStr(0);
        this.SetInt(0);
        this.SetSta(0);
        this.SetSkillPoints(50);
    }
                          Type "+" to spend your available skillpoints.
                                Type "Logout" to Log Out.
+
Your current stats are 
Strength 0.0
Stamina 0.0
Intelligence 0.0
Dexterity 0.0
Please select the attribute you want to increase. You have 50.0 available.
d
Dexterity
Your Dexterity is 0.0
How many points in Dexterity?
45
You have put 45.0 into Dexterity
Your new dexterity is 45.0
+
Your current stats are 
Strength 0.0
Stamina 0.0
Intelligence 0.0
Dexterity 0.0
public SetAttributes() {
        this.SetDex(0);
        this.SetStr(0);
        this.SetInt(0);
        this.SetSta(0);
        this.SetSkillPoints(50);
    }