Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Sample execution log Program Behavior Welcome to the CSE143 Assassin Manager In this assessment, you will write a What name file do you want to
Sample execution log Program Behavior Welcome to the CSE143 Assassin Manager In this assessment, you will write a What name file do you want to use this time? names3.txt class AssassinManager that keeps Do you want the names shuffled? (y)? n track of who is stalking whom and the history of who killed whom in Current kill ring: games of Assassin. You will main- Athos is stalking Porthos tain two linked lists: Porthos is stalking Aramis a list of people currently alive Aramis is stalking Athos (the "kill ring") and Current graveyard: . a list of those who have next victim? Aramis been assassinated (the "grave- Current kill ring: yard"). Athos is stalking Porthos Porthos is stalking Athos As people are assassinated, you will Current graveyard: move them from the kill ring to the Aramis was killed by Porthos graveyard by rearranging links be- tween nodes. The game ends when next victim? Athos only one node remains in the kill ring, representing the winner Game was won by Porthos Final graveyard is as follows: A client program called AssassinMain Athos was killed by Porthos has been written for you. It reads a Aramis was killed by Porthos file of names, shuffles the names, and constructs an object of your class AssassinManager. 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). AssassinMain calls methods of the AssassinManager class to carry out the tasks involved in administering the game. Assassin Manager To implement your lists, you must use our AssassinNode class provided in Ed without modification. The class is summarized here: AssassinNode class public class Assassinode { public final String name; // this person's name public String killer; // name of who killed this person (null if alive) public AssassinNode next; // next node in the list public AssassinMode(String name) {...} publie AssassinNode (String nane, AssassinNode next) { ... ) In class section we have been looking at nodes of type ListNode (or IntListNode) that have just two fields: a field called data of type int and a field called next that points to the next value in the list. The AssassinNode class has three fields. The first two are fields for storing data called name and killer (they are used to store the name of a player and the name of the person who assassinated that player). The third field is called next and it serves the same purpose as the next field in the ListNode class. Your AssassinManager class 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 (null if empty) Note that a requirement of this assessment is that you have exactly these two fields and no others. Your AssassinManager class should have the following constructor: public AssassinManager (List names) This constructor should initialize a new assassin manager over the given list of people. Note that you should not save the list parameter itself as a field, nor modify the list. Instead, you should build your own kill ring of list nodes that contains these names in the same order. If the list is empty, you should throw an Illegal ArgumentException. For example, if the given list contains ("John", "Sally", "Fred"), your initial kill ring should represent that John is stalking Sally who is stalking Fred who is stalking John (in that order). You may assume that the names are non-empty, non-null strings and that there are no duplicates. Your AssassinManager class should also implement the following methods: public void printKillRing() This method should print the names of the people in the kill ring, one per line, indented by four spaces, as X is stalking Y". If the game is over, then instead print "X is stalking X". For example, using the kill ring from the example game on the first page of this spec, the output is: Joe is stalking Sally Sally is stalking Jim Jim is stalking Carol Carol is stalking Chris Chris is stalking Joe If the game is over and Chris is the winner, so Chris is the only name in the kill ring, the output is: Chris is stalking Chris public void printGraveyard() This method should print the names of the people in the graveyard, one per line, with each line indented by four spaces, with output of the form "X was killed by Y". It should print the names in the opposite of the order in which they were assassinated (most recently assassinated first, then next most recently assassinated, and so on). It should produce no output if the graveyard is empty. For example, using the kill ring from above, if Jim is killed, then Chris, then Carol, the output is: Carol was killed by Sally Chris was killed by Carol Jim was killed by Sally public boolean killingContains (String name) This method should return true if the given name is in the current kill ring and false otherwise. It should ignore case in comparing names, so, "salLY" should match a node with a name of "Sally". public boolean graveyard Contains (String name) This method should return true if the given name is in the current graveyard and false otherwise. It should ignore case in comparing names; so, "CaRoL" should match a node with a name of "Carol". public boolean gameOver() This method should return true if the game is over (i.e. the kill ring contains exactly one person) and false otherwise public String winner() This method should return the name of the winner of the game, or null if the game is not over yet. public void kill(String name) This method should record the assassination of the person with the given name, transferring the person from the kill ring to the front of the graveyard. This operation should not change the relative order of the kill ring (i.e. the links of who is stalking whom should stay the same other than the person who is being killed). This method should ignore case in comparing names. A node remembers who killed the person in its killer field, and you must set the value of this field. Your method should throw an IllegalStateException if the game is over, or throw an IllegalArgumentException if the given name is not part of the kill ring. If both of these conditions are true, the IllegalStateException takes precedence. Sample execution log Program Behavior Welcome to the CSE143 Assassin Manager In this assessment, you will write a What name file do you want to use this time? names3.txt class AssassinManager that keeps Do you want the names shuffled? (y)? n track of who is stalking whom and the history of who killed whom in Current kill ring: games of Assassin. You will main- Athos is stalking Porthos tain two linked lists: Porthos is stalking Aramis a list of people currently alive Aramis is stalking Athos (the "kill ring") and Current graveyard: . a list of those who have next victim? Aramis been assassinated (the "grave- Current kill ring: yard"). Athos is stalking Porthos Porthos is stalking Athos As people are assassinated, you will Current graveyard: move them from the kill ring to the Aramis was killed by Porthos graveyard by rearranging links be- tween nodes. The game ends when next victim? Athos only one node remains in the kill ring, representing the winner Game was won by Porthos Final graveyard is as follows: A client program called AssassinMain Athos was killed by Porthos has been written for you. It reads a Aramis was killed by Porthos file of names, shuffles the names, and constructs an object of your class AssassinManager. 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). AssassinMain calls methods of the AssassinManager class to carry out the tasks involved in administering the game. Assassin Manager To implement your lists, you must use our AssassinNode class provided in Ed without modification. The class is summarized here: AssassinNode class public class Assassinode { public final String name; // this person's name public String killer; // name of who killed this person (null if alive) public AssassinNode next; // next node in the list public AssassinMode(String name) {...} publie AssassinNode (String nane, AssassinNode next) { ... ) In class section we have been looking at nodes of type ListNode (or IntListNode) that have just two fields: a field called data of type int and a field called next that points to the next value in the list. The AssassinNode class has three fields. The first two are fields for storing data called name and killer (they are used to store the name of a player and the name of the person who assassinated that player). The third field is called next and it serves the same purpose as the next field in the ListNode class. Your AssassinManager class 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 (null if empty) Note that a requirement of this assessment is that you have exactly these two fields and no others. Your AssassinManager class should have the following constructor: public AssassinManager (List names) This constructor should initialize a new assassin manager over the given list of people. Note that you should not save the list parameter itself as a field, nor modify the list. Instead, you should build your own kill ring of list nodes that contains these names in the same order. If the list is empty, you should throw an Illegal ArgumentException. For example, if the given list contains ("John", "Sally", "Fred"), your initial kill ring should represent that John is stalking Sally who is stalking Fred who is stalking John (in that order). You may assume that the names are non-empty, non-null strings and that there are no duplicates. Your AssassinManager class should also implement the following methods: public void printKillRing() This method should print the names of the people in the kill ring, one per line, indented by four spaces, as X is stalking Y". If the game is over, then instead print "X is stalking X". For example, using the kill ring from the example game on the first page of this spec, the output is: Joe is stalking Sally Sally is stalking Jim Jim is stalking Carol Carol is stalking Chris Chris is stalking Joe If the game is over and Chris is the winner, so Chris is the only name in the kill ring, the output is: Chris is stalking Chris public void printGraveyard() This method should print the names of the people in the graveyard, one per line, with each line indented by four spaces, with output of the form "X was killed by Y". It should print the names in the opposite of the order in which they were assassinated (most recently assassinated first, then next most recently assassinated, and so on). It should produce no output if the graveyard is empty. For example, using the kill ring from above, if Jim is killed, then Chris, then Carol, the output is: Carol was killed by Sally Chris was killed by Carol Jim was killed by Sally public boolean killingContains (String name) This method should return true if the given name is in the current kill ring and false otherwise. It should ignore case in comparing names, so, "salLY" should match a node with a name of "Sally". public boolean graveyard Contains (String name) This method should return true if the given name is in the current graveyard and false otherwise. It should ignore case in comparing names; so, "CaRoL" should match a node with a name of "Carol". public boolean gameOver() This method should return true if the game is over (i.e. the kill ring contains exactly one person) and false otherwise public String winner() This method should return the name of the winner of the game, or null if the game is not over yet. public void kill(String name) This method should record the assassination of the person with the given name, transferring the person from the kill ring to the front of the graveyard. This operation should not change the relative order of the kill ring (i.e. the links of who is stalking whom should stay the same other than the person who is being killed). This method should ignore case in comparing names. A node remembers who killed the person in its killer field, and you must set the value of this field. Your method should throw an IllegalStateException if the game is over, or throw an IllegalArgumentException if the given name is not part of the kill ring. If both of these conditions are true, the IllegalStateException takes precedence
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started