Groups with No Data

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

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?