Answer:

  1. How will the user indicate if group has no data?
    • By starting the group with a count of "0".
  2. Will the program run correctly if one or more groups has no data?
    • Yes—the loop body for that group will not execute.

Groups with No Data

Here is what the data should look like if group "A" has no data in it, and group "B" has four test scores in it:

0          
4          
78
82
91
84

Here is what the program writes out for this data:

C:\users\default\JavaLessons>java TestGroups
File name? student.data
Group A  has no students
Group B average: 83.75

The program will also work correctly if neither group has data. This might seem like a situation that will never occur, but programs should be written with the expectation that defective data (or unlikely data) will occur.

QUESTION 13:

Instead of a header that says how much data is in each group, could each group end with a sentinel value?