Highlights
Learning objectives of this practical session
To be able to design and implement in Python basic classes that require simple inheritance. To be able to use readily available Stack and Queue ADTs. To be able to use and modify UnitTest code. To continue practicing the implementation of correct, high quality and well documented code.
Important requirements
For this prac, you are required to:
Use the names provided for internal and external methods, as we will use them in our testing harnesses. Provide appropriate documentation for each ftle, class, function, and method you deftne or modify. For any method where you are asked to extend the Unit Testing methods in the test harness, you must include at least three extra test cases per test method, each testing its behaviour in a different situation (e.g., if you were asked to test a sorting method, you would want to test its behaviour for a sorted list, a reversed sorted list, an empty list, a mixed list, etc). and with a comment that indicates what the situation is.
Question 1
The aim of this question is to assess your knowledge in creating abstract classes. To do this, we ask you to create an army.py file that contains an abstract class called Fighter with two integer variables called life and experience, and the following methods:
init (self, life: int, experience: int) -> None: it appropriately initialises the variables using the amounts received as input. Remember to validate the inputs (by precondition, they both must be greater or equal to 0). is alive(self) -> bool: it returns True if the fighter’s life is greater than 0, False otherwise. lose_life(self, lost_life: int) -> None: it decreases the life of the unit by the amount indi- cated by lost life (by precondition, must be 0). gain_experience(self, gained_experience: int) -> None: it increases the experience of the unit by the amount indicated by gained experience (by precondition, must be 0). get experience(self) -> int: it returns the experience of the unit. get speed(self) -> int: it returns the speed of the unit. get cost(self) -> int: it returns the cost of the unit. attack damage(self) -> int: it returns the amount of damage performed by the unit when it attacks defend(self, damage: int) -> None: it decreases the life of the unit by the amount lost (if any) after defending from an attack that inflicted the amount of damage indicated by damage (by precon- dition, must be 0).
str (self) -> str: it returns a string indicating the type of unit, its current life and experience, with format "Soldier life = X and experience = Y" for a soldier with X life and Y experience, "Archer life = X and experience = Y" for an archer with X life and Y experience, and "Ca alr life = X and experience = Y", for a cavalry with X life and Y experience, fighter. Make sure you follow this exact format, as it will be needed for the testing harness.
Question 2
The aim of this question is to assess your knowledge in creating derived, non-abstract classes, and to continue assessing your knowledge in implementing code that is correct, high quality and well documented. To do this we ask you to create three non-abstract classes Soldier, Archer, and Cavalry, which are derived from the class Fighter. Each class will need to hold the cost of that unit appropriately, so that the value is the same across all objects of that class. Some of the methods in Fighter will need to be overridden, some inherited. Make sure the implementation of each class follows the values/formulae given in the table above. Also, their init methods should make appropriate use of the parent class.
Add extra tests to test_task2.py to test the init method of each class, and also to test their attack damage and defend methods
This Computer Science Assignment has been solved by our Computer Science Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.
Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.