Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Assignment 1

This is a light and easy introduction into the project. Remember to read the complete project description in order to understand the general context and for further details. You can download a jar file (and required sample input file) for a project which meets the requirements of the project description but will not follow the same implementation as we will use in this course. Use IntelliJ to create a Maven project and install ErrorProne.

In this first assignment you will create two classes, Room and Guard, in an appropriate package that have the following properties:

  • A Room can contain some number of Guards, stored in an ArrayList (be sure to store the Guard itself, not a String or some other representation of it!);
  • Every Guard must know about its Room (i.e., it needs to have a Room reference);
  • Every Room and every Guard must have a name and description;
  • Room has a public String toString() method that returns the name of the Room, its description and the names of all Guards in the Room. (hint: Room‘s toString() method should call each Guard‘s toString() method);
  • The Room class should have a public constructor that takes two Strings (the name of the Room, and the description of the Room), and a public void addGuard(Guard g) method that adds a Guard to the Room. Be sure to think about what needs to change about the Guard being assigned to the Room, and the Room it is being assigned to;
  • The Guard class should have a public constructor that takes two Strings (the name of the Guard, and the description of the Guard ).
  • The Guard class should have a public String inspectString() method which returns a String containing the name and description of the Guard.

In this assignment you may not use any static methods or fields – we will need the ability to have more than one Room and Guard as the project moves forward! Remember to use good practices. For example, don’t access fields directly from other classes, use getter/setter methods (i.e., referencers).

Create a third class (call it Main) which contains a main method implementing test cases for the above criteria. Be sure it contains tests for the “hard” cases, e.g., testing Room‘s toString where a Room contains more than one Guard. Be sure you are happy with your output and that it looks nice – you won’t have to think about prettying it up later on!

You will submit your assignment via Brightspace. To submit, zip your entire project directory (the top-level folder in the zip should be the one which contains src, target, etc.) I will be using my own driver class which tests various aspects of this assignment, so make sure your public methods/fields/classes are named exactly as described above. My driver will use Maven and ErrorProne, so be sure your project does not have any ErrorProne errors or warnings. If you have a warning you think is actually OK, leave a note in the Brightspace submission about it and I’ll give some feedback.