python类设计(类方法和变量,实例方法和变量@classme
一.代码实现
二.题目要求
代码实现:
class Company:
num = 0
name = []
def init(self,Company_name,Desc,Profit,TotalSales,TotalCost,EmployeeName):
self.Company_name = Company_name
self.Desc = Desc
self.Profit = Profit
self.TotalSales = TotalSales
self.TotalCost = TotalCost
self.EmployeeName = EmployeeName
self.Employee_number = len(self.EmployeeName)
self.class.num += 1
self.class.name.append(Company_name)
#
def recuitment(self,r_name,r_salary):
self.EmployeeName.append(r_name)
self.TotalCost += r_salary
self.Employee_number += 1
def fire(self,f_name,f_salary):
self.EmployeeName.remove(f_name)
self.TotalCost -= f_salary
self.Employee_number -= 1
def advertise(self,ad_cost):
self.TotalCost += ad_cost
def s_security(self,s_cost):
self.TotalCost += s_cost*self.Employee_number
def tax(self,t_cost):
self.TotalCost += t_cost*self.Employee_number
def sale(self,sale_number,profit_rate,price):
self.TotalSales += sale_number * price
self.Profit += sale_number * price * profit_rate
def get_employee(self):
return self.EmployeeName
def get_profit(self):
return self.Profit
@classmethod
def get_num(cls):
return cls.num
@classmethod
def get_name(cls):
return cls.name
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
c = Company(‘C’,‘Company C’,0,12,12,[‘Lilei’,‘xiaoHong’])
c.recuitment(‘Tom’,4)
c.fire(‘xiaoHong’,3)
c.advertise(0.5)
c.s_security(0.2)
c.tax(0.1)
c.sale(10,0.3,100)
print(c.Company_name)
print(c.TotalCost)
print(c.get_employee())
Company.get_name()
print(Company.num)
题目要求:
设计一个公司类,完成以下要求,并实例化不同对象进行验证
类变量
类下公司的总个数,类下实例的名称列表
类方法
返回公司类共有多少个公司实例
返回公司类的公司实例有名称列表
实例变量
公司名,简介,利润,销售额,总成本,雇员姓名
实例方法:
招聘人才(每招一个人会有成本产生,影响该实例雇员列表,人数,总成本)
解雇人员(每解雇一个人会有成本产生,影响该实例雇员列表,人数 ,总成本)
公司广告推广(影响该实例总成本)
交社保(按公司雇员总人数计算,影响该实例总成本)
交税(按公司雇员总人数计算,影响该实例总成本)
销售(按销售件数价格计算销售额,利润按销售额利润率进行计算利润。)
获取公司雇员列表
获取公司净利润
code是原创,题目来自七月在线的课程:https://www.julyedu.com/course/getDetail/144/P8uXrH1KmPC440m5GGK8SWDG
---------------------
作者:Marina-ju
来源:CSDN
原文:https://blog.csdn.net/weixin_43055882/article/details/90144028
版权声明:本文为博主原创文章,转载请附上博文链接!