Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

undefined An example of the the character class is already made in this question: https://www.chegg.com/homework-help/questions-and-answers/problem-storytelling-whether-mythic-tales-novels-movies-video-games-important-characters-s-q68004628?trackid=NjSNiMRM class Character: This is a class for creating a

image text in transcribedimage text in transcribedundefinedimage text in transcribed

image text in transcribed An example of the the character class is already made in this question: https://www.chegg.com/homework-help/questions-and-answers/problem-storytelling-whether-mythic-tales-novels-movies-video-games-important-characters-s-q68004628?trackid=NjSNiMRM

class Character: """ This is a class for creating a Character. Attributes: __name (string): Name of the Character __description (string): Description of the Character __superpower (string): Superpower of the Character __attack (float): Attack points of the character ranging from 1-10 __health (int): Health points of the Character ranging from 1-100 """ def __init__(self, name, desc, superpower, attack, health): """ The constructor for Character class. Parameters: name (string): Name of the Character desc (string): Description of the Character superpower (string): Superpower of the Character attack (float): Attack points of the character ranging from 1-10 health (int): Health points of the Character ranging from 1-100 """ self.__name=name self.__description=desc self.__superpower=superpower self.__attack=attack self.__health=health def getName(self): """ The getter for name attribute Parameters: None Returns: __name: Name of the character """ return self.__name def getDescription(self): """ The getter for name attribute Parameters: None Returns: __description: Description of the character """ return self.__description def getSuperpower(self): """ The getter for superpower attribute Parameters: None Returns: __superpower: Superpower of the character """ return self.__superpower def getAttack(self): """ The getter for attack attribute Parameters: None Returns: __attack: Attack points of the character """ return self.__attack def getHealth(self): """ The getter for health attribute Parameters: None Returns: __health: Health points of the character """ return self.__health def setDescription(self, desc): """ The setter for Description attribute Parameters: desc (string): Description of the Character """ self.__description=desc def setAttack(self, attack): """ The setter for attack attribute. Checks if the paramater is in valid range, and sets only after that Parameters: attack (float): Attack points of the character ranging from 1-10 """ if(attack>=1 and attack 

The Problem In storytelling, whether it is in mythic tales, novels, movies or video games, it is important that characters have a set of common attributes that work within the setting of the story. Most of the times characters don't exist in isolation but as part of larger groups. In this assignment you will create a squad (or gang) of such characters. Because a squad will be conformed by different characters, in this assignment you must reuse the Character class you created for Assignment 1. Specifically, the Squad class will be composed by four instances of the Character class. There will be one leader and three members. The Squad class should have the following: 1. A name for the squad. 2. Four different characters (one of which should be the leader). 2 3. The class constructor will receive the name of the squad and the four members, the first member should be the leader. 4. You must use name mangling to make all these instance variables inaccessible from outside the class. 5. There must be a getter for the name of the squad, but no setter. The name can't be changed after creating a squad. 6. The class must contain a method squad_size that will return the number of members in the squad (including the leader, thus after creation it should be 4). 7. There must be a mutator method add_member that receives a member and adds it to the squad. 8. There must be a mutator method remove_member that receives a member and removes it from the squad. If the leader of the squad is removed then the first member becomes the new leader. If a squad has only one remaining member then that member can't be removed. Thus, if this method receives as input the only remaining member, or a character that doesn't belong to the squad, then the method should do nothing. 9. You must implement a get_member method that receives an index and returns the correspond- ing member, index 0 will refer to the leader, index 1 to the first member, and so on. 10. You must also implement the __str__ method for printing the squad's info in a format similar to the one shown in the example. You should implement this method by reusing (calling) the - str._ method from the Character class. 11. You must implement a save_to_disk method that prints the squad's info to a file in text format. The info saved to disk should be the exact same info returned by the __str__ method from the Squad class. 12. You must also provide appropriate docstring documentation for classes and methods. 13. You must provide a driver script that creates four characters and add them to a squad and save the squad to disk. Then you should create a new character, add this new character to the squad and save the new squad to disk. Finally you should remove two characters from the squad, one of which should be the leader; then save the squad to disk and print it to console. Driver Script and Sample Run Continuing with our setting of the Wild West, we start by creating four different characters as shown in Figure 1: Billy the Kid, Diana Gold, Frank the Creep and James Montgomery. Then we create our squad, which we named as A weird gang, and save it to disk. After that we create a new character for Johnny Silverado, add him to the squad, and save the squad to a different file. The final part of the driver removes two characters from the squad: Frank the Creep and the leader Billy the Kid. After removing the squad leader, the first member should become the new leader. We finally save the squad to a different file and print it to console. 3 from character import Character from squad import Squad # First we create the four initial characters for the squad henry = Character("Billy the Kid", "A dangerous outlaw", "Gunfighter", 3.2, 82) diana = Character("Diana Gold", "The richest merchant of the west", "Merchant", 5.4, 54) frank = Character("Frank the Creep", "Knows his knifes", "Butcher", 4.1, 40) james = Character("James Montgomery", "The fastest gun in the west", "Hired Gun", 2.1, 88) # We create the squad and save it to disk squad = Squad("A weird gang", henry, diana, frank, james) squad.save_to_disk("squad_day1.txt") # Johnny joins the squad johnny = Character("Johnny Silverado", "Fast and Furious", "Town Marshal", 2.9, 98) squad.add_member(johnny) squad.save_to_disk("squad_day2.txt") # and we lost the Billy and Frank the Butcher :( squad.remove_member(frank) squad.remove_member(henry) # Diana should now become the leader squad.save_to_disk("squad_day3.txt") print(squad) Figure 1: Driver program for testing the Squad class. Figure 2 shows the output of running the driver program. You can see that after removing Billy and Frank the squad has now Diana as the leader and two more members. You can also see the format used to print the squad of the squad, and the information for each character. Notice that the character information is printed in the same format as in the Character class. 4 *** A weird gang *** LEADER: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 1: James Montgomery - The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 MEMBER 2: Johnny Silverado - Fast and Furious Profession: Town Marshal Draw speed: 2.9 Aim: 98 Process finished with exit code 0 Figure 2: Output for running the driver. squad_day 1.txt x *** A weird gang *** LEADER: Billy the Kid - A dangerous outlaw Profession: Gunfighter Draw speed: 3.2 Aim: 82 MEMBER 1: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 2: Frank the Creep - Knows his knifes Profession: Butcher Draw speed: 4.1 Aim: 40 MEMBER 3: James Montgomery - The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 9 10 11 12 13 15 16 17 Figure 3: Content of the first file. The Problem In storytelling, whether it is in mythic tales, novels, movies or video games, it is important that characters have a set of common attributes that work within the setting of the story. Most of the times characters don't exist in isolation but as part of larger groups. In this assignment you will create a squad (or gang) of such characters. Because a squad will be conformed by different characters, in this assignment you must reuse the Character class you created for Assignment 1. Specifically, the Squad class will be composed by four instances of the Character class. There will be one leader and three members. The Squad class should have the following: 1. A name for the squad. 2. Four different characters (one of which should be the leader). 2 3. The class constructor will receive the name of the squad and the four members, the first member should be the leader. 4. You must use name mangling to make all these instance variables inaccessible from outside the class. 5. There must be a getter for the name of the squad, but no setter. The name can't be changed after creating a squad. 6. The class must contain a method squad_size that will return the number of members in the squad (including the leader, thus after creation it should be 4). 7. There must be a mutator method add_member that receives a member and adds it to the squad. 8. There must be a mutator method remove_member that receives a member and removes it from the squad. If the leader of the squad is removed then the first member becomes the new leader. If a squad has only one remaining member then that member can't be removed. Thus, if this method receives as input the only remaining member, or a character that doesn't belong to the squad, then the method should do nothing. 9. You must implement a get_member method that receives an index and returns the correspond- ing member, index 0 will refer to the leader, index 1 to the first member, and so on. 10. You must also implement the __str__ method for printing the squad's info in a format similar to the one shown in the example. You should implement this method by reusing (calling) the - str._ method from the Character class. 11. You must implement a save_to_disk method that prints the squad's info to a file in text format. The info saved to disk should be the exact same info returned by the __str__ method from the Squad class. 12. You must also provide appropriate docstring documentation for classes and methods. 13. You must provide a driver script that creates four characters and add them to a squad and save the squad to disk. Then you should create a new character, add this new character to the squad and save the new squad to disk. Finally you should remove two characters from the squad, one of which should be the leader; then save the squad to disk and print it to console. Driver Script and Sample Run Continuing with our setting of the Wild West, we start by creating four different characters as shown in Figure 1: Billy the Kid, Diana Gold, Frank the Creep and James Montgomery. Then we create our squad, which we named as A weird gang, and save it to disk. After that we create a new character for Johnny Silverado, add him to the squad, and save the squad to a different file. The final part of the driver removes two characters from the squad: Frank the Creep and the leader Billy the Kid. After removing the squad leader, the first member should become the new leader. We finally save the squad to a different file and print it to console. 3 from character import Character from squad import Squad # First we create the four initial characters for the squad henry = Character("Billy the Kid", "A dangerous outlaw", "Gunfighter", 3.2, 82) diana = Character("Diana Gold", "The richest merchant of the west", "Merchant", 5.4, 54) frank = Character("Frank the Creep", "Knows his knifes", "Butcher", 4.1, 40) james = Character("James Montgomery", "The fastest gun in the west", "Hired Gun", 2.1, 88) # We create the squad and save it to disk squad = Squad("A weird gang", henry, diana, frank, james) squad.save_to_disk("squad_day1.txt") # Johnny joins the squad johnny = Character("Johnny Silverado", "Fast and Furious", "Town Marshal", 2.9, 98) squad.add_member(johnny) squad.save_to_disk("squad_day2.txt") # and we lost the Billy and Frank the Butcher :( squad.remove_member(frank) squad.remove_member(henry) # Diana should now become the leader squad.save_to_disk("squad_day3.txt") print(squad) Figure 1: Driver program for testing the Squad class. Figure 2 shows the output of running the driver program. You can see that after removing Billy and Frank the squad has now Diana as the leader and two more members. You can also see the format used to print the squad of the squad, and the information for each character. Notice that the character information is printed in the same format as in the Character class. 4 *** A weird gang *** LEADER: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 1: James Montgomery - The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 MEMBER 2: Johnny Silverado - Fast and Furious Profession: Town Marshal Draw speed: 2.9 Aim: 98 Process finished with exit code 0 Figure 2: Output for running the driver. squad_day 1.txt x *** A weird gang *** LEADER: Billy the Kid - A dangerous outlaw Profession: Gunfighter Draw speed: 3.2 Aim: 82 MEMBER 1: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 2: Frank the Creep - Knows his knifes Profession: Butcher Draw speed: 4.1 Aim: 40 MEMBER 3: James Montgomery - The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 9 10 11 12 13 15 16 17 Figure 3: Content of the first file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions