Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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 ( A gos BD 000 FB 10 # 3 $ 4 A % 5 6 & 7 00 * 9 0 E R T Y P 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 - strmethod from the Character class. I 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 samad and caus REAL 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 character soort Character free squad cort Squad free character Import Character fro squad inport Squad Farat create the four anatsal characters for the sound henry - Character("Billy the Kad". "A dangerous outlau", "Gunfighter", 3.2. 82) diana - Character("Diana Gold", "The richest merchant of the west", "Merchant", 5.4, 54) frank = Character("Frank the Creep", "Knons his knifes", "Butcher", 4.1, 48) janes - Character(James Montgomery", "The fastest gun in the west", "Hired Gun", 2.1, 88) create the cod and save it to ask squad = Squad("A weird gang", henry, diana, frank, janes) squad, save. to disk("squad dayi.txt") Jan 19 the soud Johnny = Character("Johnny Silverado", "Fast and Furious", "Town Marshal", 2.9, 98) squad.add member(johnny) squad.save_to_disk("squad_day2.txt") tost the Billy and Frane the Butcher :( squad.removeenber(frank) squad.recove_member Cherry) 3D 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. Figures 3, 4 and 5 show the contents for the three text files saved by the driver program. Very important note: you are not supposed to create the exact same squad and characters as in this example. You must create your own class with your own attributes, mutators and valid ranges. In a setting other than the Wild West. G A *** 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 @ Figure 2: Output for running the driver. squad_day 1.txt *** 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 25 JA AS The fastest gun in the west Aim: 48 MEMBER 3: James Montgomery Profession: Hired Gun Draw speed: 2.1 Ain: 88 Figure 3: Content of the first file. 5 squad_day2.txt *** A weird gang *** LEADER: Billy the Kid - A dangerous outlaw Profession: Gunfighter Dran speed: 3.2 Ain: 82 MEMBER 1: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Ain: 54 25 A 4 @ squad_day2.txt *** 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 MEMBER 4: Johnny Silverado - Fast and Furious Profession: Town Marshal Draw speed: 2.9 Aim: 98 2 squad_clay3.txt *** 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 Figure 5: Content of the third file. d Python file should be named as problem.py where the # is the problem number. 25 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 ( A gos BD 000 FB 10 # 3 $ 4 A % 5 6 & 7 00 * 9 0 E R T Y P 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 - strmethod from the Character class. I 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 samad and caus REAL 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 character soort Character free squad cort Squad free character Import Character fro squad inport Squad Farat create the four anatsal characters for the sound henry - Character("Billy the Kad". "A dangerous outlau", "Gunfighter", 3.2. 82) diana - Character("Diana Gold", "The richest merchant of the west", "Merchant", 5.4, 54) frank = Character("Frank the Creep", "Knons his knifes", "Butcher", 4.1, 48) janes - Character(James Montgomery", "The fastest gun in the west", "Hired Gun", 2.1, 88) create the cod and save it to ask squad = Squad("A weird gang", henry, diana, frank, janes) squad, save. to disk("squad dayi.txt") Jan 19 the soud Johnny = Character("Johnny Silverado", "Fast and Furious", "Town Marshal", 2.9, 98) squad.add member(johnny) squad.save_to_disk("squad_day2.txt") tost the Billy and Frane the Butcher :( squad.removeenber(frank) squad.recove_member Cherry) 3D 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. Figures 3, 4 and 5 show the contents for the three text files saved by the driver program. Very important note: you are not supposed to create the exact same squad and characters as in this example. You must create your own class with your own attributes, mutators and valid ranges. In a setting other than the Wild West. G A *** 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 @ Figure 2: Output for running the driver. squad_day 1.txt *** 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 25 JA AS The fastest gun in the west Aim: 48 MEMBER 3: James Montgomery Profession: Hired Gun Draw speed: 2.1 Ain: 88 Figure 3: Content of the first file. 5 squad_day2.txt *** A weird gang *** LEADER: Billy the Kid - A dangerous outlaw Profession: Gunfighter Dran speed: 3.2 Ain: 82 MEMBER 1: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Ain: 54 25 A 4 @ squad_day2.txt *** 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 MEMBER 4: Johnny Silverado - Fast and Furious Profession: Town Marshal Draw speed: 2.9 Aim: 98 2 squad_clay3.txt *** 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 Figure 5: Content of the third file. d Python file should be named as problem.py where the # is the problem number. 25

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

Recommended Textbook for

Intelligent Image Databases Towards Advanced Image Retrieval

Authors: Yihong Gong

1st Edition

1461375037, 978-1461375036

More Books

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago