using python suppose ypu are working on defining a new class called Employee. co
ID: 3836780 • Letter: U
Question
using python
suppose ypu are working on defining a new class called Employee. complete the following:
you will have to decide which attributes should be class-level and which attributes will be instance-level.
-nextEmpID #hold the last employee id that was assigned
-empID
-empName
-number of employees whose salary exceeds the averageSalary
-empSalary
-averageSalary of 10000
remember that every time an object of type Employee is instantiated, you will need to update some of the class-level attributes.NOTE: do NOT writte getters or setters or other methods.
just provide:
-the code that implements and maintain any class-level attributes correctly
-the constructor method
Explanation / Answer
class-leve Attributes:-->
(i)nextEmpID #hold the last employee id that was assigned
(ii)averageSalary of 10000
(iii)number of employees
instance-level.:-->
(i)empID
(ii) empSalary
(iii)empName
class Employee:
'Common base class for all employees'
numberOfEmp = 0
nextEmpId=0
averageSalary =0
def __init__(self,empId, name, salary):
self.name = name
self.salary = salary
self.empId= empId
Employee.nextEmpId=self.empId
def displayEmployee(self):
print "Name : ", self.name, ", Salary: ", self.salary, "EmpId ",self.empId,
"This would create first object of Employee class"
emp1 = Employee(2,"Zara", 2000)
"This would create second object of Employee class"
emp2 = Employee(3,"Manni", 5000)
emp1.displayEmployee()
emp2.displayEmployee()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.