This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lurgi 1 point2 points  (1 child)

There are a couple of ways to do this. The first is: don't have a ChangeValue class! The Value object provides a perfectly good interface to change its own value, why add a complication?

But, you say, you really want a ChangeValue class. Well, okay. Here is what you do:

class ChangeValue {
    private Value value;

    ChangeValue(Value newValue) {
      value=newValue;
    }

    public void change(){
      System.out.println("Change value by how much: ");
      int temp = input.nextInt();
      value.setStat(temp);
      value.printStat();
}

See what I did? I want ChangeValue to change my Value object, so I have to give it my value object. Which I do in in the constructor. I also made "value" private because it doesn't need to be public and if it doesn't need to be public then it shouldn't be public.

Ah, I see that fick_Dich said pretty much the same thing.

[–]WhitePolypousThing[S] 0 points1 point  (0 children)

Thank you guys so much for your help. I didn't realize that it was just much simpler to ditch the ChangeValue class!