CSE 143: Computer Programming II
This assignment will assess your mastery of the following objectives:
- Implement a well-designed Java class to meet a given specification.
- Create and manipulate a linked list.
- Manipulate linked list nodes in an efficient manner.
- Follow prescribed conventions for code quality, documentation, and readability.
Overview: The Assassin Game
“Assassin” is a game often played on college campuses. Each person playing has a particular target that
he/she is trying to “assassinate.” Generally “assassinating” a person means finding them on campus in
public and acting on them in some way (e.g. saying “You’re dead,” squirting them with a water gun, or
tagging them). One of the things that makes the game more interesting to play in real life is that initially
each person knows only who they are assassinating; they don’t know who is trying to assassinate them,
nor do they know whom the other people are trying to assassinate.
Assassin Rules
- You start out with a group of people who want to play the game
- A circular chain of assassination targets (called the “kill ring” in this program) is established.
- When someone is assassinated, the links need to be changed to “skip” that person. That is, the
person who was assassinated passes their target on to the person who assassinated them.
Example Game of Assassin
Let’s walk through an example with five people playing: Carol, Chris, Jim, Joe, Sally. We might start
with Joe stalking Sally, Sally stalking Jim, Jim stalking Carol, Carol stalking Chris, and Chris stalking
Joe. In the actual linked list that implements this kill ring, Chris’s next reference would benull. But,
conceptually we can think of it as though the next person after Chris is Joe, the front person in the list.
1 | Note the last |
Here is a picture of this “kill ring”:
1 | Joe Sally Jim Carol Chris |
1 | front |
Then, suppose Sally assassinates Jim. Sally needs a new target, so we give her Jim’s target: Carol. The
kill ring becomes:
1 | Joe Sally Carol Chris |
1 | front |
If the first person in the kill ring is assassinated, the front of the list must adjust. If Chris kills Joe, the
list becomes:
1 | Sally Carol Chris |
1 | front |
Summer 2021
Take-home Assessment 3: AssassinManager due J uly 1 5, 2021 11: 59 pm
1 | Sample execution log |
1 | What name file do you want to use this time? names3.txt |
1 | Current kill ring: |
1 | next victim? Aramis |
1 | Current kill ring: |
1 | next victim? Athos |
1 | Game was won by Porthos |
Program Behavior
In this assessment, you will write a
class AssassinManagerthat keeps
track of who is stalking whom and
the history of who killed whom in
games of Assassin. You will main-
tain two linked lists:
- a list of people currently alive
(the “kill ring”) and - a list of those who have
been assassinated (the “grave-
yard”).
As people are assassinated, you will
move them from the kill ring to the
graveyard by rearranging links be-
tween nodes. The game ends when
only one node remains in the kill ring,
representing the winner.
A client program calledAssassinMain
has been written for you. It reads a
file of names, shuffles the names, and
constructs an object of your classAssassinManager. This main program then asks the user for the names
of each victim to assassinate until there is just one player left alive (at which point the game is over and
the last remaining player wins). AssassinMaincalls methods of theAssassinManagerclass to carry
out the tasks involved in administering the game.
AssassinManager
To implement your lists, you must use ourAssassinNodeclass provided in Ed without modification. The
class is summarized here:
1 | AssassinNode class |
1 | public AssassinNode(String name) { ... } |
1 | You cannot |
In class section we have been looking at nodes of typeListNode(orIntListNode) that have just two
fields: a field calleddataof typeintand a field callednextthat points to the next value in the list. The
AssassinNodeclass has three fields. The first two are fields for storing data callednameandkiller
(they are used to store the name of a player and the name of the person who assassinated that player).
The third field is callednextand it serves the same purpose as the next field in theListNodeclass.
YourAssassinManagerclass must have exactly the following fields:
- a reference to the front node of the kill ring
- a reference to the front node of the graveyard (nullif empty)
Note that a requirement of this assessment is that you have exactly these two fields and no others.
1 | Do NOT add a |
YourAssassinManagerclass should have the following constructor:
1 | public AssassinManager (List<String> names) |
1 | Do not change |
1 | For example, if the given list contains["John", "Sally", "Fred"], your initial kill ring should |
YourAssassinManagerclass should also implement the following methods:
1 | public void printKillRing () |
1 | XandYare |
1 | For example, using the kill ring from the example game on the first page of this spec, the output is: |
1 | Indent the |
1 | For example, using the kill ring from above, if Jim is killed, then Chris, then Carol, the output is: |
1 | public boolean killRingContains (String name) |
1 | public boolean graveyardContains (String name) |
1 | public boolean gameOver () |
1 | public String winner () |
1 | public void kill (String name) |
1 | Exceptions |
1 | Try to write |
1 | Your method should throw an IllegalStateException if the game is over, or throw an |
Thekillmethod is the hardest to complete, so we strongly suggest you write it last. Use the jGRASP
debugger andprintlnstatements liberally to debug problems in your code. You will likely have a lot of
NullPointerExceptionerrors, infinite loops, etc. and will have a very hard time tracking them down
unless you are comfortable with debugging techniques.
1 | Be sure to |
Implementation Guidelines
The learning objectives for this assessment are explicitly related to manipulating linked lists. To that end,
you are limited in how you may implement the operations required forAssassinManager. Specifically,
you must adhere to the following rules:
- You may not construct any arrays,ArrayLists,LinkedLists,Stacks,Queues, or other data
structures; you must use instances ofAssassinNodeand manipulate them yourself. - If there arennames in the list ofStrings passed to your constructor, you must create exactlyn
newAssassinNodeobjects in your constructor. You may not create any additional node objects,
and you may not create node objects in any other methods. In addition, you may not modify the
namefield of nodes after they have been created. As people are assassinated, you will move the
existing node from the kill ring to the graveyard by changing references. You must not create any
new node objects or change thenamefield of the nodes. - You may declare as many references toAssassinNodeobjects (i.e. local variables of typeAssassinNode
as you like.AssassinNoderefernces are not node objects and therefore do not count against the
limit ofnnodes described above. - Your constructor should be “efficient” in the sense that it should not use any nested loops to
construct the initial kill ring. (We will learn in class that this is calledO(n)time, wherenis the
number of names in the list.)
Circular Lists
Some students try to store the kill ring using a “circular” linked list (where the list’s final element stores a
next reference back to the front ). It is significantly more difficult to write bug-free code using a circular
list. There is no need to use a circular list for this assessment, because you can always get back to the front
via the fields of yourAssassinManager. If you feel strongly that you want to use a circular list, you may,
but we believe it will make the program significantly more difficult to write, and we strongly discourage
it. We will not provide assistance in office hours to help you implement the circular list solution.
jGRASP Debugger
We recommend that you use the jGRASP debugger for this assessment, even if you are primarily working
in another IDE or in Ed. The jGRASP debugger has a structure viewer to see what your list looks like by
dragging one of your fields from the debug window outside the window. By default the viewer won’t show
you the name in each node (it will show a “?” instead). Fix this by clicking the wrench icon, then in
the “Value Expressions” box, type:node.name, Click OK, and you should see the names in the nodes.
You can also drag the width scrollbar to see the names better.
Code Quality Guidelines
In addition to producing the behavior described above, your code should be well-written and meet all
expectations described in thegrading guidelines, Code Quality Guide, andCommenting Guide. For this
assessment, pay particular attention to the following elements:
Avoid Redundancy
Factor out any
redundancy in
If you find that multiple methods in your class do similar things, you should create helper method(s) to your methods.
capture the common code. All helper methods should be declared asprivate.
Data Fields
Properly encapsulate your objects by making data your fieldsprivate. Avoid unnecessary fields; use
fields to store important data of your objects but not to store temporary values only used in one place.
Fields should always be initialized inside a constructor or method, never at declaration.
Exceptions
The specified exceptions must be thrown correctly in the specified cases. Exceptions should be thrown
as soon as possible, and no unnecessary work should be done when an exception is thrown. Exceptions
should be documented in comments, including the type of exception thrown and under what conditions.
Commenting
Each method should have a header comment including all necessary information as described in the
Commenting Guide. Comments should be written in your own words (i.e. not copied and pasted from
this spec) and should not include implementation details.
Running and Submitting
If you believe your behavior is correct, you can submit your work by clicking the “Mark” button in the Ed
assessment. You will see the results of some automated tests along with tentative grades. These grades
are not final until you have received feedback from your TA.
You may submit your work as often as you like until the deadline; we will always grade your most recent
submission. Note the due date and time carefully— work submitted after the due time will not be
accepted.
Getting Help
If you find you are struggling with this assessment, make use of all the course resources that are available
to you, such as:
- Reviewing relevant examples fromclass
- Reading the textbook
- Visitingoffice hours
- Posting a question on themessage board
Collaboration Policy
Remember that, while you are encouraged to use all resources at your disposal, including your classmates,
all work you submit must be entirely your own. In particular, you should NEVER look at a solution
to this assessment from another source (a classmate, a former student, an online repository, etc.). Please
review thefull policyin the syllabus for more details and ask the course staff if you are unclear on whether
or not a resource is OK to use.
Reflection
In addition to your code, you must submit answers to short reflection questions. These questions will
help you think about what you learned, what you struggled with, and how you can improve next time.
The questions are given in the fileAssassinManagerReflection.txtin the Ed assessment; type your
responses directly into that file.