Extra Credit Project 1 - Solve Times
CPE 103
The webmaster of www.quotepuzzles.com has hired you to write a Java
program to process some data he has gathered from users who visit his
website.
You are given a text data file that contains a large
number of records. Each record (line of the
file) has two fields, separated by a semicolon. The first field
is the IP address of someone who visited the website. The second
field is the number of seconds that person spent solving a puzzle using
an interactive applet on the site. For example, the first few lines of
the file are:
129.65.17.135;67
24.17.9.139;217
199.243.168.134;427
199.243.168.134;966
199.243.168.134;518
69.111.244.226;100
24.17.9.139;259
This data shows that visitor 24.17.9.139 solved two
puzzles; the first one in 217 seconds and the second in 259 seconds.
You are to write a program to read the data file and compute the IP
address of the visitor with the fastest average solving
time.
(You may assume there will be exactly one fastest time.)
For example, assuming that visitor 199.243.168.134 appears
only three times in the file, their average solving time would be 427 +
966 + 518 / 3 = 637.
Also compute the number of puzzles solved by the fastest solver.
Since the data file contains confidential information, the file will
remain in the possession of the instructor. You must construct
your own test data to test your program.
Class Design
Your class must be named SolveTimes and must
contain the following public methods:
public void
findWinner(InputStream streamIn) - process the input data.
public String getWinner() - return the IP
address of the winner.
public double getAverage() - return the
average solving time of the winner.
public int getSolvedCount() - return the
number of puzzles solved by the winner.
public static void main(String[] args) -
run the application, accepting the name of a data file as the command
line argument.
Unit Testing
Here is an example unit test:
import java.io.*;
public class ExampleTest extends junit.framework.TestCase
{
public void testWithSmallFile() throws
FileNotFoundException
{
SolveTimes app = new
SolveTimes();
FileInputStream fs = new
FileInputStream(new File("data.txt"));
app.findWinner(fs);
assertEquals("Incorrect
winner","19.234.56.789",app.getWinner());
assertEquals("Incorrect
average",71.3,app.getAverage(),0.1);
assertEquals("Incorrect
solved count",7,app.getSolvedCount());
}
}
Submission
You may submit your work either of two ways:
- (Preferred) Bring your source code to the instructor's office
hours and you can demonstrate it with the instructor's test data.
- (Alternate, if office hours are busy) Submit it via
Web-CAT. You will need to submit any data files needed by the
junit test
to Web-CAT in a zip file along with your
source code and unit test files.
Submit your time log either during office hours or at a regular
class meeting.
This assignment is worth one-third of a regular project in extra credit
points.