Skip to content

Instantly share code, notes, and snippets.

@Jun711
Created February 16, 2018 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jun711/63100ace848adf4f0dfb727a071b3af4 to your computer and use it in GitHub Desktop.
Save Jun711/63100ace848adf4f0dfb727a071b3af4 to your computer and use it in GitHub Desktop.
TestDome - UserInput - Java Class
public class UserInput {
public static class TextInput {
protected StringBuilder inputSB;
public TextInput() {
inputSB = new StringBuilder();
}
public void add(char c) {
this.inputSB.append(c);
}
public String getValue() {
return this.inputSB.toString();
}
}
public static class NumericInput extends TextInput {
public NumericInput() {
super();
}
@Override
public void add(char c) {
if (Character.isDigit(c)) {
this.inputSB.append(c);
}
}
}
public static void main(String[] args) {
TextInput input = new NumericInput();
input.add('1');
input.add('a');
input.add('0');
System.out.println(input.getValue());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment