In this homework, you will implement a simulation of Piazza with a web-like query interface. You should imagine that your application runs on a server (except that the data is stored in Java data structures and not a database). Clients communicate by issuing queries and updates. In an actual web application, clients (such as smartphones or the JavaScript code in a browser that paints the user interface) issue queries using HTTP, which we simulate.
A request has a command (such as login
) and parameters which are key=value pairs (such as username=fred
). To enter a request, type the command, the parameters (one line at a time), and a blank line. The system will process the command and print a reply, which starts with the status (OK
or ERROR
), then 0 or more lines of key=value pairs, and a blank line. In a phone or browser, a user interface would then be updated based on the replies, but we won't do that.
You are given classes Request.java, Reply.java, PiazzaSimulation.java that take care of the protocol handling. You may not modify these classes. (They will be overwritten with the original when your code is tested.) Your task is to define classes Post
, Response
, FollowupDiscussion
, and User
. You may supply additional classes if you desire.
When you test the program, it is best to put commands into a file such as this test1.in sample. Then run your program as
java -classpath bin PiazzaSimulation < test1.in
The grader will have an expected output file (such as this test1.expected) and run
mkdir /tmp/hw3 cp student/*.java /tmp/hw3 cp horstmann/{Request,Reply,PiazzaSimulation}.java horstmann/*.{in,expected} /tmp/hw3 cd /tmp/hw3 javac *.java java PiazzaSimulation < test1.in > test1.out diff test1.out test1.expected
The test case passes if there is no output, indicating that the results are identical. Otherwise, the test case fails with no partial credit.
That doesn't mean that you should develop on the command line. Use Eclipse for comfort and convenience. In Eclipse, this post shows you how you can attach the file for debugging.
When you make the Eclipse project, first populate a directory hw3
in your repo with the five downloaded files:
cd ~/cs151 mkdir hw3 cp ~/Downloads/{Request,Reply,PiazzaSimulation}.java hw3 cp ~/Downloads/*.{in,expected}.java hw3 git add hw3
Then make a new Eclipse project and point it to the existing directory. Make sure that you aren't making an additional src
subdirectory.
Provide javadoc for all classes, interfaces, and methods. Use CheckStyle to verify that you have not forgotten any comments. Download checkstyle-8.17-all.jar and place it inside a directory checkstyle
in your your home directory. Download this configuration file into and also place it into ~/checkstyle
. Then run
java -classpath ~/checkstyle/checkstyle-8.17-all.jar com.puppycrawl.tools.checkstyle.Main -c ~/checkstyle/checkstyle-cs151.xml *.java
Submit the homework cleanly, in a directory hw3
, with no files other than the Java source and test files. No *.class files, no .metadata, .project, .classpath.