[go: up one dir, main page]

0% found this document useful (0 votes)
73 views8 pages

SDA Assignment#1

The document describes an assignment to write a program that generates statements for customers' charges at a video store. It includes code written in Python with classes like Video, NewReleaseVideo, ChildrensVideo, and Customer. The code uses object-oriented principles like inheritance, polymorphism, and encapsulation. It also explains the modular approach taken to divide the program into logical components and describes code refactoring techniques used to improve the design, readability, and reusability of the code.

Uploaded by

Waleed Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views8 pages

SDA Assignment#1

The document describes an assignment to write a program that generates statements for customers' charges at a video store. It includes code written in Python with classes like Video, NewReleaseVideo, ChildrensVideo, and Customer. The code uses object-oriented principles like inheritance, polymorphism, and encapsulation. It also explains the modular approach taken to divide the program into logical components and describes code refactoring techniques used to improve the design, readability, and reusability of the code.

Uploaded by

Waleed Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

NUST

School of Electrical Engineering and


Computer Science (SEECS)

SE-211 Software Design and Architecture

Assignment# 1

Group Members: 5

Name: CMS ID:


Waleed Ahmed 372675

Fahd Ahmad 365665

Syed Hassan Abbas 367416

Zain-ul-Abideen 366482

Ahmed Abdullah 367962

Submission Date: 07/02/2023

Submitted to: Ms. Zunera Zahid


Table of Contents
Question:........................................................................................................................................2
Code:..............................................................................................................................................2
UML – Diagram:..............................................................................................................................4
 Handwritten:.......................................................................................................................4
 Complete UML Diagram:.....................................................................................................5
Explanation:....................................................................................................................................5
 Modular Approach:.............................................................................................................5
 Code Refactoring:...............................................................................................................6
Question:
Write a program to print out a statement of a customer’s charges at a
video store. There are several classes that represent various video
elements.

Write code clearly highlighting modular approach and code


refactoring.

Code: (Python Programming Language)

class Video:
    def _init_(self, title, rental_price):
        self.title = title
        self.rental_price = rental_price

    def get_charge(self, days_rented):


        return self.rental_price * days_rented

    def get_points(self, days_rented):


        return 1

class NewReleaseVideo(Video):
    def _init_(self, title):
        super()._init_(title, 3)

    def get_charge(self, days_rented):


        return self.rental_price * days_rented * (days_rented > 1)

    def get_points(self, days_rented):


        return 2 * (days_rented > 1)

class ChildrensVideo(Video):
    def _init_(self, title):
        super()._init_(title, 1.5)

    def get_charge(self, days_rented):


        return 1.5 + (days_rented - 3) * 1.5 if days_rented > 3 else self.rental_price * days_rented

class Customer:
    def _init_(self, name):
        self.name = name
        self.rentals = []

    def add_rental(self, rental):


        self.rentals.append(rental)

    def statement(self):
        total_amount, frequent_renter_points = 0, 0
        result = "Rental Record for " + self.name + "\n"

        for rental in self.rentals:


            # Determine amounts for each line
            video = rental.video
            days_rented = rental.days_rented
            amount = video.get_charge(days_rented)
            frequent_renter_points += video.get_points(days_rented)

            # Show figures for this rental


            result += "\t" + video.title + "\t" + str(amount) + "\n"
            total_amount += amount

        # Add footer lines


        result += "Amount owed is " + str(total_amount) + "\n"
        result += "You earned " + \
            str(frequent_renter_points) + " frequent renter points"
        return result
UML – Diagram:
 Handwritten:
 Complete UML Diagram:

Explanation:
 Modular Approach:
A modular approach to building a program for a video store receipt generator
would involve dividing the program into different components, each of which
handles a specific functionality. Some of the modules that could be included in
such a program are:

1. Customer module - to store information about customers such as name,


address, and membership status.
2. Video module - to store information about the videos such as title, genre,
rental fee, and availability.
By dividing the program into separate modules, each of which handles a specific
functionality, the program becomes easier to maintain and modify, and new
features can be added more easily. Additionally, modular design allows for
individual components to be tested and validated before being integrated into the
overall program, ensuring a high level of quality and reliability.

 Code Refactoring:
Refactoring is the process of improving the design of existing code, without
changing its external behaviour. Here's a refactoring approach for the video store
receipt generator program:

1. Extract methods - identify and extract repeated code into separate methods,
making the code more readable and reusable. In this code, we have used
get_charge(), get_point() in videos.

2. Create and use classes - create classes for the different components of the
program, such as Customer, Video, ChildrenVideos, and
newReleaseVideos. This will promote encapsulation and reduce coupling
between components, making the code easier to maintain and modify.

3. Use inheritance and polymorphism - create a base class for related


components and use inheritance to extend the functionality of specific
components. Also, use polymorphism to handle different types of objects in a
generic way. In this code, we have a two inheritance classes which is as
follows:

Video  ChildrenVideos, newReleaseVideos.

4. Remove redundancy - identify and remove redundant code, improving the


program's efficiency and reducing the potential for bugs.

5. Use design patterns - apply well-known design patterns to improve the overall
structure of the program, such as the Factory pattern for creating objects, or
the Singleton pattern for creating a single instance of a class.
By following these refactoring steps, the video store receipt generator program
can be improved to have a more robust, scalable, and maintainable design.

You might also like