Java Reference
In-Depth Information
Exercise 4.71 Correct all the errors in the following method.
/**
* Print all the values in the marks array that are
* greater than mean.
* @param marks An array of mark values.
* @param mean The mean (average) mark.
*/
public void printGreater(double marks, double mean)
{
for(index = 0; index <= marks.length; index++) {
if(marks[index] > mean) {
System.out.println(marks[index]);
}
}
}
Exercise 4.72 Modify the LogAnalyzer class so that it has a constructor that can take
the name of the log file to be analyzed. Have this constructor pass the file name to the con-
structor of the LogfileReader class. Use the LogfileCreator class to create your own
file of random log entries, and analyze the data.
Exercise 4.73 Complete the numberOfAccesses method, below, to count the total
number of accesses recorded in the log file. Complete it by using a for loop to iterate over
hourCounts :
/**
* Return the number of accesses recorded in the log
* file.
*/
public int numberOfAccesses()
{
int total = 0;
// Add the value in each element of hourCounts
// to total.
...
return total;
}
Exercise 4.74 Add your numberOfAccesses method to the LogAnalyzer class and
check that it gives the correct result. Hint : You can simplify your checking by having the ana-
lyzer read log files containing just a few lines of data. That way you will find it easier to deter-
mine whether or not your method gives the correct answer. The LogfileReader class has a
constructor with the following header, to read from a particular file:
/**
* Create a LogfileReader that will supply data
* from a particular log file.
 
Search WWH ::




Custom Search