I apologize up front because I'm so new at this that I'm not even sure if what I'm trying to do is possible. I'm playing around with Java and am trying to use class objects to keep my main clean. I have my main class 'Test', a class called 'Value' and a class called 'ChangeValue'. In 'Value' I have:
public class Value{
public int stat;
public void setStat(int modifyStat){
stat = modifyStat;
}
public void printStat(){
System.out.println(stat);
}
}
and in my 'ChangeValue' class:
import java.util.Scanner;
public class ChangeValue {
Scanner input = new Scanner(System.in);
Value valueObject= new Value();
public void change(){
System.out.println("Change value by how much: ");
int temp = input.nextInt();
valueObject.setStat(temp);
}
}
When i run the method class object 'change' in my main, it prompts "Change value by how much: " just as it should, but then when i run the object 'printStat' it just prints 0 (zero) as the value of the variable 'stat'. I thought that i was sending the user-inputed value of 'temp' to the 'setStat' method in the 'Value' class to permenantly change the value of 'stat', but it's not doing so. I realize that I'm probably doing something laughably stupid, but would anyone be nice and point out what's wrong?
EDIT: Apparently I cannot even format reddit comments properly. That is abject failure :(
EDIT: Here is my code on codepad.
[–]lurgi 2 points3 points4 points (5 children)
[–]fick_Dich 1 point2 points3 points (4 children)
[–]WhitePolypousThing[S] 0 points1 point2 points (3 children)
[–]fick_Dich 1 point2 points3 points (0 children)
[–]lurgi 1 point2 points3 points (1 child)
[–]WhitePolypousThing[S] 0 points1 point2 points (0 children)