Define a class “employee” having employee id, name and salary use accept and to-string method to display and create n employee’s data and find the total salary of all employees and find the name of the employee who is having maximum salary.
Question
Define a class “employee” having employee id, name and salary use accept and to-string method to display and create n employee’s data and find the total salary of all employees and find the name of the employee who is having maximum salary.
Solution
Here is a Python solution for your question:
class Employee:
def __init__(self, id, name, salary):
self.id = id
self.name = name
self.salary = salary
def __str__(self):
return f'Employee[id={self.id}, name={self.name}, salary={self.salary}]'
def main():
employees = []
n = int(input("Enter the number of employees: "))
for i in range(n):
id = int(input("Enter employee id: "))
name = input("Enter employee name: ")
salary = float(input("Enter employee salary: "))
employees.append(Employee(id, name, salary))
total_salary = sum(e.salary for e in employees)
print(f'Total salary of all employees: {total_salary}')
max_salary_employee = max(employees, key=lambda e: e.salary)
print(f'Employee with maximum salary: {max_salary_employee.name}')
if __name__ == "__main__":
main()
Here's how it works:
-
We define a class
Employeewith attributesid,name, andsalary. The__init__method is used to initialize these attributes and the__str__method is used to provide a string representation of the object. -
In the
mainfunction, we first ask the user for the number of employees. We then create a list ofEmployeeobjects based on the user's input. -
We calculate the total salary of all employees by using a generator expression to sum up the
salaryattribute of eachEmployeeobject in the list. -
We find the employee with the maximum salary by using the
maxfunction with a key function that returns thesalaryattribute of eachEmployeeobject. -
Finally, we print out the total salary and the name of the employee with the maximum salary.
Similar Questions
Create a Java base class called Employee. Use this class to store two double-type values that could be used to compute the salary of employees. Also,the base class should have a static variable ‘totalemp’ to keep track of the total number of employees created. Derive two specific classes called part_time and full_time from the base employee. Add a member function called as get_basic() to get the basic pay and another member called display_salary() to compute and display the salary of the employees. Using these three classes, design a program that will accept the basic pay of part_time and full_time employees interactively. Remember the two values given as input will be treated as the basic pay of the employees and the following information is used for calculating the salaries of both the part-time as well as full-time employees. Print invalid if the basic_salary of part-time employee and basic_salary of full-time employee are not met the ”Boundary Condition”Part time Full timeHRA = 20% of basic pay HRA = 30% of basic payDA = 72% of basic pay DA = 80% of basic paySalary = Basic + HRA + DA Salary = Basic + HRA + DABoundary Condition:0 < basic_salary of part-time employee <= 10000000 < basic_salary of full-time employee <= 1000000Input Format:First line to enter the basic_salary of part-time employee and basic_salary of full-time employeeOutput Format:Total salary of part-time employee and total salary of full-time employee.Total number of employees processed Sample Testcase Input-1:50007000000Sample Testcase Output-1:8900.0invalid1 Sample Testcase Input-2:30000600000Sample Testcase Output-2:42720.0110400.02 Sample Testcase Input-3:0900000Sample Testcase Output-3:invalid216000.01
Define a class Employee. Display the personal salary details of three employeesusing single inheritance
For given relation:Employee(eid, ename, address,deptname ,salary)Project(eid, pid, pname, location)(1) Display name and salary of employee who is taking maximum salary.(2) Display highest salary department wise and name of employee who is taking thatsalary.(3) Find details of employee who works on a pid equal to 10
An employee will have a name, pay_rate, and list of hours_worked.Employee class must have following methods:Constructor – takes name and pay_rate. It will also creat an empty list of hours_worked.add_hours – takes hours as a parameter and add it to the hours_worked list.salary – calculates the salary for the employe (pay_rate x total hours worked).Write a main function that will:Ask user for employee name and pay rate.Create the employee object.Ask user for the number of days the employee worked.For each day it will ask the user for number of hours that employee worked and use the add_hours function to add this to the list of hours_worked in employee class.It will display the employee data as follows (use f string to format the output):Employee Name: Joe DoePay Rate: $ 25.75 per hourTotal number of hours worked: 39.45Total Salary: $ 1015.84
Create the class Employee with name, Empid, address, mailid, mobileno as data members.Inherit the classes Asstprofessor, Associateprofessor and Professor from employee class.Add Basic Pay (BP) as the member of all the inherited classes.Calculate DA as 97% of BP, HRA as 10% of BP, PF as 12% of BP, Staff club fund as 0.1% of BP.Calculate gross salary and net salary.Generate payslip for Asstprofessor categories of employees.Calculate DA as 97% of BP, HRA as 7% of BP, PF as 13% of BP, Staff club fund as 0.1% of BP.Calculate gross salary and net salary.Generate payslip for Associateprofessor categories of employees, Create the objects for the inherited classes and invoke the necessary methods to display the Payslip.Calculate DA as 97% of BP, HRA as 4% of BP, PF as 13% of BP, Staff club fund as 0.2% of BP.Calculate gross salary and net salary.Generate payslip for Professor categories of employees,Choose the options PROGRAMMER 2.ASSISTANT PROFESSOR 3.ASSOCIATE PROFESSOR 4.PROFESSORinput
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.