Created
February 16, 2018 00:56
-
-
Save Jun711/63100ace848adf4f0dfb727a071b3af4 to your computer and use it in GitHub Desktop.
TestDome - UserInput - Java Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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