Question: Comp - 4 4 1 1 Programming Languages Assignment Task: Kotlin Programming - Procedural and Object - Oriented Programming Objective: To evaluate your understanding of
Comp Programming Languages
Assignment Task: Kotlin Programming Procedural and ObjectOriented Programming
Objective:
To evaluate your understanding of procedural and objectoriented programming OOP concepts in Kotlin. You will demonstrate your ability to write modular, reusable code using both paradigms, understanding how to solve problems with clear specifications, following guidelines and rules.
Part : Procedural Programming in Kotlin
Task Description:
You are required to write a Kotlin program using procedural programming principles ie without using any classes or objects to simulate the management of a library system. The library system should keep track of books and students. Each student can borrow up to books at a time. The program should do the following:
Book Management:
o
Define a structure to represent a book with the following attributes: title, author, and status available or borrowed
o
Allow adding new books to the library collection.
Student Management:
o
Define a structure to represent a student with attributes: name, student ID and the list of books they have borrowed.
o
Allow adding new students to the system.
Borrowing and Returning Books:
o
Allow a student to borrow a book if its available and if they havent borrowed more than books.
o
Update the books status when borrowed or returned.
o
Prevent the student from borrowing the same book twice or borrowing more than books.
Display Data:
o
Implement a procedure to display the list of books and their availability.
o
Implement a procedure to display which students have borrowed books and how many.
Comp Programming Languages
Requirements:
Use arrays or lists to store books and students.
You should not use any classes or objects for this part.
Use functions to break down tasks into manageable pieces of code.
Constraints:
Design your program in a modular way to prevent code duplication.
Make sure that students cannot borrow more than books or borrow a book thats already borrowed.
Part : ObjectOriented Programming in Kotlin
Task Description:
You are now required to refactor your procedural program from Part into an objectoriented design. Use classes, objects, and OOP principles such as encapsulation, inheritance, and polymorphism where appropriate. You need to add more functionality to the library system, incorporating the following changes:
Encapsulation and Inheritance:
o
Create a base class Person with attributes like name and id
o
Derive the Student class from Person and add an attribute for the maximum number of books they can borrow.
o
Add a new type of user, such as Librarian, derived from Person. The Librarian should have the ability to manage addremove books and students.
Book Categories:
o
Create a hierarchy of book categories using inheritance. For example:
Book base class
Fiction, NonFiction, and Magazine derived classes
o
Each type of book should have additional attributes eg Fiction books have genre, Magazines have issue number
o
Implement a method in the Book class and its derived classes to print detailed information about the book.
Polymorphism and Overriding:
Comp Programming Languages
o
Use method overriding to customize the behavior of borrowing or returning books based on the type of book. For example, students can borrow Fiction books for days and Magazines for only days.
o
Implement polymorphism when displaying book information, ensuring that calling a method on a Book reference displays the correct details based on whether the book is Fiction, NonFiction, or Magazine.
Exception Handling:
o
Handle cases where a student tries to borrow more than books or when a book is not available by raising custom exceptions and catching them in the program.
Requirements:
Use proper OOP design principles: encapsulation, inheritance, and polymorphism.
Ensure that the program is wellstructured, with appropriate use of classes and objects.
Implement error handling using Kotlin exceptions.
Constraints:
You must implement at least one abstract class or interface.
You should implement at least one custom exception class.
Part : Comparative Analysis
Task Description:
Write a word report comparing your implementations in Part and Part Focus on the following points:
How did the structure of your code change from procedural to objectoriented?
What are the advantages and disadvantages of each approach in terms of modularity, readability, and maintainability?
Discuss how encapsulation, inheritance, and polymorphism helped organize the OOP version.
Reflect on any challenges you faced during the refactoring process.
Submission Guidelines:
Code:
o
Part : Procedural Kotlin code marks
o
Part : Objectoriented Kotlin code marks
Comp Programming Languages
Report: Submit a word report
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
