posted 5 years ago
That's a matter of style really. By convention, setters take one parameter and assign that parameter to a member variable. They may also do validation ... range checking and so forth ... but they don't usually do anything else. You could follow that convention by calling the setter something else, like outputEditedString(String, int). In that case, you wouldn't need the member variables. There's no sense setting them unless you're going to use them later. On the other hand, you could have member variables for the original string and the n, and then have getters and setters for those, or just set them via a constructor. Your outputEditedString() in that case wouldn't need parameters, since it would use the member variables instead. In neither case do you need the String result in the member data. You aren't using it, and you use result locally in your method to mean something else, so that's confusing.