Sen 306 Practical Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

NAME: ODEBUNMI FIYINFOLUWA OLUWOLE

COURSE: SEN 306 PRACTICAL ASSIGNMENT


MATRIC NO: IFT/17/2449

1a. Draw the Class Diagram of the Class Table

EMPLOYEE

- emp_id: int
- emp_name: string
- emp_address: string
- emp_mobile: string

+ ADD(): void
+ DELETE(): void
+ EDIT(): void

b. Write an OOP program in any language of your choice to implement the Class

Will write in python

SOLUTION

class Employee:

def __init__(self, emp_id, emp_name, emp_address, emp_mobile):

self.emp_id = emp_id

self.emp_name = emp_name

self.emp_address = emp_address

self.emp_mobile = emp_mobile

def display_info(self):

print(f"Employee ID: {self.emp_id}")

print(f"Name: {self.emp_name}")

print(f"Address: {self.emp_address}")

print(f"Mobile: {self.emp_mobile}")
print()

def add_employee(self, new_employee):

# Assuming new_employee is an instance of the Employee class

# You might want to implement error checking and uniqueness validation

employee_list.append(new_employee)

def delete_employee(self, emp_id_to_delete):

global employee_list

employee_list = [employee for employee in employee_list if employee.emp_id != emp_id_to_delete]

def edit_employee(self, emp_id_to_edit, new_name, new_address, new_mobile):

for employee in employee_list:

if employee.emp_id == emp_id_to_edit:

employee.emp_name = new_name

employee.emp_address = new_address

employee.emp_mobile = new_mobile

# Example Usage

employee_list = []

# Creating instances of the Employee class

employee1 = Employee(101, "Akinosun", "FUTA", "09066123011")

employee2 = Employee(102, "Olu", "Oshinle", "08066543342")

employee3 = Employee(103, "Bunmi", "Ijapo", "07089754327")

employee4 = Employee(104, "Olawale", "Oke-Aro", "08077123087")


# Adding employees to the list

employee_list.extend([employee1, employee2, employee3, employee4])

# Displaying employee information before deletion

print("Employee Information Before Deletion:")

for employee in employee_list:

employee.display_info()

# Deleting an employee

employee2.delete_employee(102)

# Displaying employee information after deletion

print("Employee Information After Deletion:")

for employee in employee_list:

employee.display_info()

# Editing an employee

employee1.edit_employee(101, "Akinosun Updated", "New FUTA Address", "11111111111")

# Displaying employee information after editing

print("Employee Information After Editing:")

for employee in employee_list:

employee.display_info()
c. Write a program to create an array object of the class table to store all the data items shown in

the table.

SOLUTION

class Employee:

def __init__(self, emp_id, emp_name, emp_address, emp_mobile):

self.emp_id = emp_id

self.emp_name = emp_name

self.emp_address = emp_address

self.emp_mobile = emp_mobile

def display_info(self):

print(f"Employee ID: {self.emp_id}")

print(f"Name: {self.emp_name}")

print(f"Address: {self.emp_address}")

print(f"Mobile: {self.emp_mobile}")

print()

# Creating an array object to store data items (instances of Employee class)

employee_array = [

Employee(101, "Akinosun", "FUTA", "09066123011"),

Employee(102, "Olu", "Oshinle", "08066543342"),

Employee(103, "Bunmi", "Ijapo", "07089754327"),

Employee(104, "Olawale", "Oke-Aro", "08077123087")

# Displaying employee information from the array


for employee in employee_array:

employee.display_info()

2. An application that determines whether any of several department store customers has

exceeded his or her credit limit on a charge account is to be developed. For each customer, the

following facts are available:

a. Account number

b. Balance at the beginning of the month

c. Total of all items charged by the customer for the month

d. Total of all credits applied to the customer’s account this month

e. Allowed credit limit

The program should input all these facts as integers, calculate the new balance as:

New balance= Beginning balance + charges-credits

Display the new balance and determine whether the new balance exceeds the customer’s credit

limit. For those customers whose credit limit is exceeded, the program should display the

message “Credit Limit Exceeded”

a. Draw the activity diagram of credit limit determination

b. Draw the sequence diagram for view new balance

c. Implement the credit limit determination module in any language of your choice

SOLUTION

a. Draw the activity diagram of credit limit determination

(Start)

v
[Input Facts]

[Calculate New Balance]

[Check Credit Limit]

[Display Results]

(End)

b. Draw the sequence diagram for view new balance

Customer Program

| |

| Input |

|-----------> |

| |

| Calculate |

| <----------- |

| |
| Display |

| <-----------|

| |

c. Implement the credit limit determination module in any language of your choice

Python

class Customer:

def __init__(self, account_number, beginning_balance, charges, credits, credit_limit):

self.account_number = account_number

self.beginning_balance = beginning_balance

self.charges = charges

self.credits = credits

self.credit_limit = credit_limit

def calculate_new_balance(self):

return self.beginning_balance + self.charges - self.credits

def check_credit_limit(self):

new_balance = self.calculate_new_balance()

if new_balance > self.credit_limit:

return "Credit Limit Exceeded"

else:

return f"New Balance: {new_balance}"

# Example usage:

customer_data = {

"account_number": 1234,

"beginning_balance": 1000,

"charges": 500,

"credits": 300,

"credit_limit": 1200
}

customer = Customer(**customer_data)

result = customer.check_credit_limit()

print(result)

You might also like