Computer Programming 2
Welcome to your first assignment!
This assignment is designed to test your understanding of the Object-Oriented Programming (OOP) concepts we have covered in the past few weeks. You will be creating a simple library management system.
Instructions:
Learning Outcome 1 (Analyse) & Learning Outcome 2 (Develop)
This part of the assessment addresses Learning Outcome 1 and Learning Outcome 2. You will analyse the basic requirements of a single entity within the engineering application (a library book) to establish software requirements for a class. You will then develop a software solution for this component by creating a Python class, demonstrating an effective and efficient use of the RAD tool capabilities (in this case, Python's OOP features).
Let's start by creating a simple Book class to develop a single component of our application.
Task:
Book.__init__ method that accepts title, author, and isbn as arguments.__init__ method, assign these arguments to attributes with the same names.display_info that prints the book's details in a user-friendly format.Example of how to create a class:
class MyClass:
def __init__(self, arg1, arg2):
self.attribute1 = arg1
self.attribute2 = arg2
def my_method(self):
print(f"Attribute 1: {self.attribute1}, Attribute 2: {self.attribute2}")
Task:
Now, create two instances (objects) of your Book class with different details.
Example of how to create an object:
my_object = MyClass("Hello", "World")
my_object.my_method()
Learning Outcome 1 (Analyse) & Learning Outcome 2 (Develop)
This part continues to address Learning Outcome 1 and Learning Outcome 2. You will analyse the engineering application further to identify commonalities and differences between item types, providing a structured interpretation of the application requirements. You will then develop a more sophisticated software solution using inheritance, which is a key RAD technique for creating reusable and organized code.
In a real-world library application, there are more than just books. There are DVDs, magazines, etc. We can use inheritance, a powerful RAD technique, to create a more organized and structured software solution.
Task:
LibraryItem with title and item_id attributes, and a display_info method.Book class to inherit from LibraryItem. The Book class should also have author and isbn attributes.DVD that also inherits from LibraryItem. The DVD class should have director and duration (in minutes) attributes.display_info method in both Book and DVD classes to display their specific details. Use the super() function to call the parent's display_info method.Example of Inheritance:
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
print("Some generic animal sound")
class Dog(Animal):
def __init__(self, name, breed):
super().__init__(name)
self.breed = breed
def speak(self):
print("Woof!")
Learning Outcome 1 (Analyse) & Learning Outcome 2 (Develop)
This part focuses on Learning Outcome 1 and Learning Outcome 2. You will analyse the functional requirements of the overall system, such as managing a collection of items. Following this analysis, you will develop a software solution by creating a Library class that acts as a controller for your application components, demonstrating a valid application of RAD tools and components working together.
Now let's develop a Library class to manage all our library items, based on an analysis of the application's requirements.
Task:
Library.Library class should have a catalog attribute, which should be a list to store LibraryItem objects.add_item(self, item) to add a LibraryItem object to the catalog.remove_item(self, item_id) to remove an item from the catalog by its item_id.display_catalog(self) to loop through the catalog and display the information for each item.Learning Outcome 2 (Develop) & Learning Outcome 3 (Evaluate)
This final part primarily assesses Learning Outcome 2 and introduces Learning Outcome 3. You will develop and demonstrate a software solution by integrating all previously created components. Furthermore, by testing the system's functionality, you will evaluate the performance of a RAD software solution. This task requires you to technically appraise the performance of your solution by confirming it behaves as expected and to identify areas for improvement if it does not.
Now, let's use the classes you've created to demonstrate a software solution. You will then evaluate its performance by testing its core functionality.
Task:
Library object.Book objects and two DVD objects. Give them unique item_ids.Library object.Once you have completed all the parts, make sure to save your notebook and submit the .ipynb file.