The user interface contains two types of user input controls: TextInput, which accepts all characters and Numeric Input, which accepts only digits.
1. Implement the class TextInput that contains:
O Public method def add(c : Char) - concatenates the given character to the current value
O Public method def getValue(): String - returns the current value
Implement the class NumericInput that:
O Inherits from TextInput
O Overrides the add method so that each non-numeric character is ignored
For example, the following code should output "10":
$input = new NumericInput();
$input->add('1');
$input->add('a');
$input->add('0');
echo $input->getValue();
The code skeleton is provided below:
<?php
class TextInput
{
}
class Numericinput
{
{
//$input = new NumericInput();
//$input->add('1');
//$input->add('a');
//$input->add('0');
//echo $input->getValue();

Respuesta :

Answer:

Explanation:

public class Main

{

private static String val; //current val

public static class TextInput

{

public TextInput()

{

val= new String();

}

public void add(char c)

{

if(val.length()==0)

{

val=Character.toString(c);

}

else

{

val=val+c;

}

}

public String getvalue()

{

return val;

}

}

public static class NumericInput extends TextInput

{

Override

public void add(char c)

{

if(Character.isDigit(c))

{

//if character is numeric

if(val.length()==0)

{

val=Character.toString(c);

}

else

{

val=val+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());

}

}