Java Reference
In-Depth Information
else if
(!group1.hasNext() && group2.hasNext())
//Step 8b
System.out.println("Ran out of data for "
+ "group 1 before group 2.");
else
//Step 8c
{
outfile.printf("Avg for group 1: %.2f %n",
(avgGroup1 / numberOfCourses));
outfile.printf("Avg for group 2: %.2f %n",
(avgGroup2 / numberOfCourses));
}
group1.close();
//Step 9
group2.close();
//Step 9
outfile.close();
//Step 9
}
public static double
calculateAverage(Scanner inp)
{
double
totalScore = 0.0;
int
numberOfStudents = 0;
int
score = 0;
double
courseAvg;
score = inp.nextInt();
while
(score != -999)
{
totalScore = totalScore + score;
numberOfStudents++;
score = inp.nextInt();
}
//end while
courseAvg = totalScore / numberOfStudents;
return
courseAvg;
}
//end calculate Average
public static void
printResult(PrintWriter outp,
String courseId,
int
groupNo,
double
avg)
{
if
(groupNo == 1)
outp.print(""+ courseId + ");
else
outp.print("
");
outp.printf("%9d %15.2f%n", groupNo, avg);
}
}
Search WWH ::
Custom Search