BIS1003-Introduction to Programming Intensive

profileAbdulmalek
BIS1003_Workshop_Topic10.pdf

BIS1003 Introduction to Programming

Workshop 10

Topic 10: Object-oriented programming

Apply and test your knowledge of the current and previous topics by attempting the questions below.

Completing these questions will help you to succeed in your subject.

Complete workshop-10 activities and submit your work during the workshop session.

Workshop Questions

1. Employee data

a) Write a Python class called Employee that maintains some employee data: employee ID,

employee name, employee worked hours and employee pay rate. Pay rate values and worked

hours are a float number with two decimal points. You need to create accessors methods for

employee ID, employee name, employee worked hours and employee pay rate. Do not create

any mutators methods for this question.

b) Create a method get_total_pay that calculates and returns the total pay of an employee. Total

pay = worked hours x pay rate.

c) Create an __str__ method representing an employee data in this format: Name: Thair Dalain,

Worked hours: 30, Pay rate: $100, Total pay: $300.

d) In your main() function, instantiate the employee class for two different employees with some

dummy data and print out those instances using print() calls.

2. Book objects

a) Create a Book class that holds these attributes: ISBN, title, author, publish year, book status.

Since books can have a different status, the book status should be a list of strings, for example

['Available', 'Reserved', 'Borrowed', 'Damaged'].

b) Create accessor methods for all attributes and create a mutator to update the book title.

c) Create another program and import the Book class to it. This program creates one or more

book objects with any sample data and then prints out those instances using accessor methods.