UserInput


OOP Public

Easy  

15min

User interface contains two types of user input controls: TextInput, which accepts all characters and NumericInput, which accepts only digits.

Implement the class TextInput that contains:

  • Public method void Add(char c) - adds the given character to the current value
  • Public method string GetValue() - returns the current value

Implement the class NumericInput that:

  • Inherits TextInput
  • Overrides the Add method so that each non-numeric character is ignored

For example, the following code should output "10":

TextInput input = new NumericInput();
input.Add('1');
input.Add('a');
input.Add('0');
Console.WriteLine(input.GetValue());
C# 5.0, .NET Framework 4.5
   

  •   Example case: System.InvalidCastException
  •   Adding various characters to TextInput: System.NullReferenceException
  •   Adding numeric characters to NumericInput: System.InvalidCastException
  •   Adding various characters to NumericInput: System.InvalidCastException