Identify the flaws / limitations in the following ConvertToNumber method:


public static bool ConvertToNumber(string str)
{
bool canConvert = false;
try
{
int n = Int16.Parse(str);

if (n != 0)
{
canConvert = true;
}
}
catch (Exception ex)
{

}
bool retval = false;
if (canConvert == true)
{
retval = true;
}
return retval;
}

Respuesta :

Answer:

Flaws and limitations identified in this program includes;

1.There was a not necessary usage of variable retrieval. Would have made use of canConvert.

2. Looking at the program, one will notice numerous typos. One of which is the fact that in JAVA we make use of Boolean instead of bool.

3.We rather use Integer.parseInt in JAVA and not Int16, cant make use of Int16.

4. The exception cant be printed

5. JAVA makes use of checkConversion instead of convertNumber as used in the program.

6. It cant work for decimal numbers, 0 and big integers.

Explanation:

See Answer for the detailed explaination of the flaws and limitations identified in the program.