Java Reference
In-Depth Information
{
if (groupNo == 1)
outp.print(""+ courseId + ");
else
outp.print("
");
outp.printf("%9d %15.2f%n", groupNo, avg);
}
Now that we have designed and defined the methods calculateAverage and
printResults , we can describe the algorithm for the method main . Before out-
lining the algorithm, however, note the following: It is quite possible that in both
input files the data is ordered according to the course IDs, but one file might have
fewer courses than the other. We discover this error only after we have processed
both files and discover that one file has unprocessed data. Make sure to check for this
error before printing the final answer—that is, the average for group 1 and group 2.
Main
Algorithm:
Method
main
1. Declare the variables (local declaration).
2. Create and initialize the variables to open the input and output files.
3. Initialize the course average for group 1 to 0.0 .
4. Initialize the course average for group 2 to 0.0 .
5. Initialize the number of courses to 0 .
6. Print the heading.
7. For each course in group 1 and group 2:
a. Get courseId1 for group 1.
b. Get courseId2 for group 2.
c.
7
if (courseId1 ! ¼ courseId2)
{
System.out.println("Data error: Course IDs do not match");
return ;
}
d.
else
{
i. Calculate the course average for group 1 (call the
method calculateAverage and pass the appropriate
parameters).
ii. Calculate the course average for group 2 (call the
method calculateAverage and pass the appropriate
parameters).
Search WWH ::




Custom Search