Comp 170 Lab 4 - WebLog Analyzer, Feb 15
Goals
- More while & for loops
- More Arrays
- Modifying classes
Overview
The existing weblog analyzer determined which hours of the day were most popular.
In this lab you will modify the analyzer to produce a report that indicates which
days of the week were most in demand.
The book version of the weblog analyzer is here.
LogEntry: add getDay()
Edit the LogEntry class to add an accessor getDay() that returns the
day of the month, 1 through 31. Follow the pattern of getHour()
and getMinute().
Weekday Array
In the LogAnalyzer class, declare and allocate an array of size 7 for the weekday data.
Call it dayCounts[].
Convert day of month to day of week
Your getDay() function returns a day numbered from 1 to 31.
You need to convert this, in the LogAnalyzer class, to a weekday.
We will number the days as Sun=0, Mon=1, ..., Sat=6.
To do this, I had to look up that May 1, 2002 (the start of the month in question
in the log data) was on a Wednesday, that is, when dayofMonth=1 then dayofWeek=3;
that is, dayofWeek = getDay() + 2. Well, sort of; as soon as you reach days ≥ 7
you need to divide by 7 and take the remainder:
(getDay() + 2) % 7
Use this as the day of the week, as the index into the array.
Analysis
Produce appropriate analogues of the existing analyzeHourlyData() and
printHourlyCounts(). You should probably just change "Hourly" to "Weekly"
in these names. I suppose you could also go with "Daily".
Busiest Day
Write a method (again in LogAnalyzer) that will return the busiest day of the week;
that is, the i<7 for which dayCounts[i] has the maximum value.
Email me your completed LogAnalyzer.java file. Although you will make one minor
change to the LogEntry class, you don't need to mail that to me.