1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| import time class School(object): """学校基类,总部校区""" def __init__(self,name,addr): self.name = name self.addr = addr self.branches = {} self.__staff_list = [] self.__bank_account_balance = 0 print("初始化校区[%s],地址:%s..." % (self.name,self.addr)) def count_staff_num(self): """统计公司各分校员工人数""" total_staff_num = len(self.__staff_list) for i in self.branches: total_staff_num += self.branches[i].count_staff_num() print("[%s]总员工数量:%s" % (self.name, total_staff_num)) return total_staff_num def pay_roll(self): """发工资""" def new_staff_enrollment(self,staff_obj): """添加新员工""" self.__staff_list.append(staff_obj) def count_total_balance(self): balance = self.__bank_account_balance for branch_name,branch_obj in self.branches.items(): balance += branch_obj.__bank_account_balance print("Total balance:",balance) def open_course(self): pass def open_class(self): pass def show_balance(self): print("[%s]账户余额:%s" %( self.name,self.__bank_account_balance)) def money_transfer_in(self,amount,from_obj,purpose): """ 收钱 :param amount: :param from_obj: :param purpose: :return: """ self.__bank_account_balance += amount print("%s,校区[%s]收到[%s]转账[%s],交费原因[%s]..." % (time.strftime("%Y-%m-%d %H:%M:%S"), self.name,from_obj.name,amount,purpose)) class BranchSchool(School): """分校""" def __init__(self,name,addr,headquater_obj): super().__init__(name,addr) self.headquater_obj = headquater_obj self.headquater_obj.branches[name] = self class Course(object): """课程类""" def __init__(self,name,fee,degree_requirement,): self.name = name self.fee = fee self.degree_requirement = degree_requirement class Class(object): """班级类""" def __init__(self,course_obj,school_obj,class_num,start_date): self.class_num = class_num self.start_date = start_date self.course_obj = course_obj self.school_obj = school_obj self.stu_list = [] print("校区[%s]开设了[%s]课程第[%s]班,开班日期[%s]..." %( school_obj.name ,course_obj.name ,class_num,start_date)) def get_class_name(self): return "%s-%s-s%s期" %(self.school_obj.name,self.course_obj.name,self.class_num) def drop_out(self,stu_obj): """退学""" self.stu_list.remove(stu_obj) print("学员[%s]从[%s]退学了...." % (stu_obj.name,self.get_class_name())) class Staff(object): """员工类""" def __init__(self,name,age,position,salary,dept,school_obj,on_board_date): self.name = name self.age = age self.position = position self.salary = salary self.dept = dept self.school_obj = school_obj self.on_board_date = on_board_date print("校区[%s]的[%s]部门在[%s]入职一名新同事[%s],职位是[%s]" % (school_obj.name ,dept,on_board_date, name,position)) school_obj.new_staff_enrollment(self) class Teacher(Staff): """讲师""" def teaching(self,class_obj): """ 上课 :param class_obj: 上课的班级 """ pass class Student(object): def __init__(self,name,age,degree,class_obj,balance): self.name = name self.age = age self.degree = degree self.class_obj = class_obj self.balance = balance self.class_obj.stu_list.append(self) def pay_tuition(self): """交学费""" self.balance -= self.class_obj.course_obj.fee self.class_obj.school_obj.money_transfer_in(self.class_obj.course_obj.fee,self,"交%s学费"%self.class_obj.get_class_name()) def __repr__(self): return "学生:%s,班级:%s" %(self.name,self.class_obj.get_class_name())
headquater = School("达外北京总部","北京凉水河一街9号") bj1 = BranchSchool("达外北京分校","北京亦庄经济技术开发区",headquater) sh = BranchSchool("达外上海分校","上海张江科技园",headquater) sh1 = BranchSchool("达外上海1分校","上海虹桥机场",sh) sh2 = BranchSchool("达外上海2分校","上海虹桥火车站",sh) sz1 = BranchSchool("达外深圳分校","深圳南山大学城1号",headquater)
staff1 = Staff("王达外",32,"CEO",60000,"总经办",headquater,"2017-05-22") staff2 = Staff("周达内",23,"HR",6000,"HR",headquater,"2018-03-12") t1 = Teacher("马骏",27,"前端开发讲师",30000,"教研部",bj1,"2018-02-26") t2 = Teacher("牛牡",25,"Python讲师",45000,"教研部",sz1,"2018-07-14") t3 = Teacher("张弛",23,"Go讲师",40000,"教研部",sh1,"2018-07-14")
py_course = Course("Python开发",21800,"本科") linux_course = Course("Linux云计算运维",19800,"专科") go_course = Course("GO开发",9800,"本科")
class1 = Class(py_course,bj1,21,"2019-07-06") class2 = Class(linux_course,sz1,4,"2019-06-16") class3 = Class(go_course,sh1,11,"2019-09-21")
stu1 = Student("孙小空",22,"本科",class1,30000) stu2 = Student("朱小戒",23,"专科",class2,25000) stu3 = Student("沙小僧",26,"本科",class3,13000) stu4 = Student("刘小贝",21,"本科",class3,10000) stu5 = Student("张小飞",21,"专科",class1,20000) for i in (stu1,stu2,stu3,stu4): i.pay_tuition() print(class3.stu_list) bj1.show_balance() sh1.show_balance() sh2.show_balance() sz1.show_balance() headquater.count_total_balance() headquater.count_staff_num() print(headquater.branches)
stu5.class_obj.drop_out(stu5)
|