Anasayfa
/
Teknoloji
/
Imagine You Are Working in a Technology Company. Your Boss Wants You to Create a Simple Application to Calculate the Annual Raises of

Soru

Imagine you are working in a technology company. Your boss wants you to create a simple application to calculate the annual raises of the employees according to their previous 3 years' sale numbers. Also, you want to store those results on a txt document. So you can print it and show it to your boss. Your program will take the employee's name sumame, employee ID, and sales for the first.second and third years as input. All fields are required. Create an employee class It should have fields for name, surname, employee ID, sales for the first month, sales for the second month, sales for the third month, amount of the raise going to be added to the employees' salaries. Use meaningfu names for the fields. Create an instance method to calculate salary raises. SalaryRaise=((25% salesOne)+ (35% salesTwo)+(40% salesThree))^ast 0.2. The remaining functionalities of the class are up to you. You can create the class the way you want it. After submitting your data show a message dialog and clear the form. Override the toString method and use it to write into the ",but file.

Çözüm

4.7 (225 Oylar)
Talip
Uzman doğrulaması
Profesyonel · 6 yıl öğretmeni

Cevap

Here's an example implementation of the `Employee` class in Python:```pythonclass Employee: def __init__(self, name, surname, employee_id, sales_one, sales_two, sales_three): self.name = name self.surname = surname self.employee_id = employee_id self.sales_one = sales_one self.sales_two = sales_two self.sales_three = sales_three self.salary_raise = 0.0 def calculate_salary_raise(self): self.salary_raise = ((0.25 * self.sales_one) + (0.35 * self.sales_two) + (0.4 * self.sales_three)) * 0.2 def __str__(self): return f"{self.name} {self.surname}, {self.employee_id}, {self.sales_one}, {self.sales_two}, {self.sales_three}, {self.salary_raise}" def save_to_file(self, filename): with open(filename, "w") as file: file.write(str(self)) print("Data saved to file successfully!") self.clear_form() def clear_form(self): self.name = "" self.surname = "" self.employee_id = "" self.sales_one = 0.0 self.sales_two = 0.0 self.sales_three = 0.0 self.salary_raise = 0.0```The `Employee` class has the following fields:* `name`: the employee's name* `surname`: the employee's surname* `employee_id`: the employee's ID* `sales_one`: the sales for the first year* `sales_two`: the sales for the second year* `sales_three`: the sales for the third year* `salary_raise`: the amount of the raise going to be added to the employee's salaryThe class also has the following methods:* `calculate_salary_raise`: calculates the salary raise based on the given formula* `__str__`: returns a string representation of the employee's data, which is used to write the data to the file* `save_to_file`: writes the employee's data to a file with the given filename* `clear_form`: clears the form by setting all fields to empty or zero valuesTo use the class, you can create an instance of the `Employee` class and call its methods like this:```pythonemp = Employee("John", "Doe", "1234", 1000, 2000, 1500)emp.calculate_salary_raise()emp.save_to_file("employee_data.txt")```This will create an instance of the `Employee` class with the given data, calculate the salary raise, save the data to a file named "employee\_data.txt", and print a message dialog saying "Data saved to file successfully!".