1 public class Q1NumberThing
2 {
3 /*************************************************************
4 * Sums all numbers in the list greater than y. *
5 * Divides the total by the magnitude of the list. *
6 * If anything is invalid, -1.0 is returned instead. *
7 **************************************************************/
8 public static double numberThing(List intList, int y)
9 {
10 if (intList == null)
11 return -1.0;
12 else
13 {
14 double sum = 0.0;
15 for(Integer nextInt: intList)
16 {
17 if(nextInt > y)
18 sum = sum + (double)nextInt;
19 }
20
21 if(sum == 0)
22 return -1.0;
23
24 double result = sum / (double)intList.size();
25 return result;
26 }
27 }
28
29 public static void main(String[] args)
30 {
31 double result = numberThing(/*parameters go here*/);
32 System.out.println(result);
33 }
34 }
Explain what is wrong with the given code. Describe the fault precisely by proposing a modification
If possible, give a test case that does not execute the fault. If not, briefly explain
why not.
If possible, give a test case that executes the fault, but does not result in an error
state. If not, briefly explain why not.
If possible give a test case that results in an error, but not a failure. If not, briefly
explain why not.
e) In the given code, describe the first error state. Be sure to describe the complete
state.