User Input


VB.NET OOP Public New

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 sub Add(c As Char) - adds the given character to the current value
  • Public function GetValue() As String - 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":

Dim input As TextInput = New NumericInput()
input.Add("1")
input.Add("a")
input.Add("0")
Console.WriteLine(input.GetValue())
VB.NET 15.0, .NET Framework 4.7
   

  •   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