Sometimes a programmer picks a sentinel value that will "never occur in the data." Of course, years later the program is used in a new situation where that special value does occur in the data and problems arise.
Here is part A of the program that will work with this type of input data file. Of course, there are some blanks for you to fill.
import java.io.*;
import java.util.Scanner;
public class TestGroupsSentinel
{
public static void main ( String[] args ) throws IOException
{
int value; // the value of the current integer
// Prompt for and open the input file
Scanner user = new Scanner( System.in );
System.out.print("File name? ");
String fileName = user.next().trim();
Scanner scan = new Scanner( new File(fileName) );
// Group "A"
int sumA = ______; // initialize the sum of scores for group "A"
int countA = ______; // initialize the group A count
while ( (value = scan.nextInt()) != -1 )
{
sumA = ______ ; // add to the sum
countA = countA + 1; // increment the count
}
if ( countA > ______ )
System.out.println( "Group A average: " + ((double) sumA)/countA );
else
System.out.println( "Group A has no students" );
Of course, you are eager to fill in those blanks.