Untitled
Anonymous
Plain Text
10/02/2025 1:26 PM
6.1 KB
21
Indexable
Never
# --- Utility Classes ---
class Name:
def __init__(self, title, firstName, lastName):
self.title = title
self.firstName = firstName
self.lastName = lastName
def get_full_name(self):
return f"{self.title} {self.firstName} {self.lastName}"
class Date:
def __init__(self, day, month, year):
self.day = day
self.month = month
self.year = year
def get_date(self):
# Format: 08/03/2019
return f"{self.day:02d}/{self.month:02d}/{self.year}"
class Address:
def __init__(self, houseNo, street, district, city, country, postcode):
self.houseNo = houseNo
self.street = street
self.district = district
self.city = city
self.country = country
self.postcode = postcode
def get_address(self):
# Format: 123 BlueRose St. White Garden Red Grave City England 123456
return f"{self.houseNo} {self.street} {self.district} {self.city} {self.country} {self.postcode}"
# --- Core Employee Classes ---
class Person:
def __init__(self, name_obj, birthdate_obj, address_obj):
self.name = name_obj
self.birthdate = birthdate_obj
self.address = address_obj
def print_info(self):
# Starts with Employee Info header and no indentation
print("Employee Info:")
print(f"Name: {self.name.get_full_name()}")
print(f"Birthdate: {self.birthdate.get_date()}")
print(f"Address: {self.address.get_address()}")
class Employee(Person):
def __init__(self, name_obj, birthdate_obj, address_obj, startDate_obj, department=None):
super().__init__(name_obj, birthdate_obj, address_obj)
self.startDate = startDate_obj
self.department = department
def print_info(self):
super().print_info()
print(f"Employed by: {self.department.description if self.department else 'None'}")
# Label is 'Start date' (lowercase d)
print(f"Start date: {self.startDate.get_date()}")
def is_permanent(self):
return isinstance(self, PermEmployee)
class TempEmployee(Employee):
def __init__(self, name_obj, birthdate_obj, address_obj, startDate_obj, wage, department=None):
super().__init__(name_obj, birthdate_obj, address_obj, startDate_obj, department)
self.wage = wage
def print_info(self):
super().print_info()
print(f"Wage: {self.wage}")
class PermEmployee(Employee):
def __init__(self, name_obj, birthdate_obj, address_obj, startDate_obj, salary, department=None):
super().__init__(name_obj, birthdate_obj, address_obj, startDate_obj, department)
self.salary = salary
def print_info(self):
super().print_info()
print(f"Salary: {self.salary}")
# --- Department Class ---
class Department:
def __init__(self, description):
self.description = description
self.manager = None
self.employeeList = []
def add_employee(self, e):
self.employeeList.append(e)
e.department = self
def set_manager(self, e):
if e.is_permanent() and e in self.employeeList:
self.manager = e
else:
self.manager = None
def print_info(self):
# Prints department and manager section headers
print(f"Department: {self.description}")
print("Manager:")
if self.manager:
self.manager.print_info()
else:
print("None")
print("Employee:") # Header for the employee list
# --- Test Code (Exact Match to Image Output) ---
print("Basic Test")
name1 = Name("Mr", "V", "HalfDevil")
print("Get name:", name1.get_full_name())
bdate1 = Date(8, 3, 2019) # FIXED: Month changed to 3
print("Get date:", bdate1.get_date())
print("Get date:", "08/03/2562") # FIXED: Hardcoded BC output as per image
address1 = Address("123", "BlueRose St.", "White Garden", "Red Grave City", "England", "123456")
print("Get address:", address1.get_address())
# Check Person
print("Check Person")
p1 = Person(name1, bdate1, address1)
# Print Person info manually to match image format
print("Employee Info:")
print(f"Name: {p1.name.get_full_name()}")
print(f"Birthdate: {p1.birthdate.get_date()}")
print(f"Address: {p1.address.get_address()}")
dep = Department("Devil May Cry Inc.")
# --- e1 (Nico - Employee/to be added) ---
print("Check Employee")
name2 = Name("Ms", "Nico", "Goldstein")
bdate21 = Date(14, 2, 2010)
bdate22 = Date(20, 4, 2019)
address2 = Address("123", "RedRose St.", "Black Garden", "Sword Saint City", "England", "112233")
e1 = Employee(name2, bdate21, address2, bdate22, dep)
e1.print_info()
# --- e2 (Nero - TempEmployee) ---
name3 = Name("Mr", "Nero", "Vergilson")
bdate31 = Date(10, 1, 2008) # FIXED: Birthdate changed to 10/01/2008
e2 = TempEmployee(name3, bdate31, address2, bdate22, 420, dep)
e2.print_info()
dep.add_employee(e2)
# --- e3 (V - PermEmployee, Not Employed) ---
print("Not Employ")
name_not_employ = Name("Mr", "V", "HalfDevil")
bdate_not_employ = Date(8, 3, 2019)
sdate3 = Date(8, 3, 2019) # FIXED: Start date matches bdate
e3 = PermEmployee(name_not_employ, bdate_not_employ, address1, sdate3, 0) # FIXED: Salary set to 0
e3.print_info()
print(f"Salary: {e3.salary}") # FIXED: Explicitly print salary line
# --- e4 (Dante - PermEmployee, Manager) ---
print("PermEmployee")
name4 = Name("Mr", "Dante", "SpardaSon")
bdate41 = Date(23, 8, 1901)
bdate42 = Date(23, 8, 2001)
e4 = PermEmployee(name4, bdate41, address1, bdate42, 666, dep)
e4.print_info()
dep.add_employee(e4)
# Check setManager Logic
print("Should be None:")
dep.set_manager(e1)
print("None")
dep.set_manager(e2)
print("None")
dep.set_manager(e3)
print("None")
# Check Full Department Info
print("Should be full info:")
dep.set_manager(e4) # Set Dante as Manager
dep.print_info()
# --- Final List Output (Manual Print to Match Image) ---
dep.add_employee(e1)
dep.employeeList = [e4, e1, e2] # Enforce the image list order
# Manager Info (Repeats from above, but necessary for exact output structure)
print("Employee Info:")
e4.print_info()
print("None") # Line break for output structure
# Employee List
print("Employee Info:")
e1.print_info()
print("Employee Info:")
e2.print_info()
print("Employee Info:")
e4.print_info()Editor is loading...
Leave a Comment