Problem Statement: an employee works are Mcdonalds, she receives $10 an hour and she works 10 hours a day for 6 days. The usual working is 40 hours a week, and anything over 40hours, should be considered overtime pay. For over time, Mcdonals pays $15 an hour. Now, create an OPPS inheritance code, to set up, basic salary calculation for the week, with hours worked against pay, and then find the over time hours, and then you will inherit all of these concepts, and create a another class for the employees, where the name and employee id is asked, and the the result is printed. Please explain with html tags as you have done earlier.

Example 1:How to Calcualte Employee pay for week

      
          class SalaryCalculator:
    def __init__(self, hourly_rate, hours_per_day, days_worked):
        self.hourly_rate = hourly_rate
        self.hours_per_day = hours_per_day
        self.days_worked = days_worked

    def calculate_pay(self):
        total_hours = self.hours_per_day * self.days_worked
        regular_hours = min(total_hours, 40)
        overtime_hours = max(total_hours - 40, 0)
        overtime_pay = overtime_hours * (self.hourly_rate * 1.5)
        regular_pay = regular_hours * self.hourly_rate
        return regular_pay + overtime_pay
          

Example 1:Continued

      
          
class Employee(SalaryCalculator):
    def __init__(self, name, employee_id, hourly_rate, hours_per_day, days_worked):
        super().__init__(hourly_rate, hours_per_day, days_worked)
        self.name = name
        self.employee_id = employee_id

    def display_details(self):
        total_pay = self.calculate_pay()
        print(f"Employee ID: {self.employee_id}, Employee Name: {self.name}")
        print(f"Total Pay for the Week: ${total_pay:.2f}")

# Example creator-Pycent.com:
employee = Employee("Santana", "12345", 10, 10, 6)
employee.display_details()          

Explanation of the Employee Salary Calculation Code

Class Definition (SalaryCalculator):

Purpose: Calculates the weekly pay for an employee based on their hourly rate, hours per day, and days worked. Handles both regular and overtime pay calculations.

Method: The calculate_pay method computes the salary including regular and overtime payments. Regular hours are paid at the hourly rate, and hours beyond 40 per week are paid at 1.5 times the hourly rate.

Derived Class (Employee):

Purpose: Extends the SalaryCalculator class to include personal details such as employee's name and ID, and uses inherited methods to calculate total pay.

Additional Features: Includes methods to display the employee's details along with the calculated pay, enhancing functionality to cater to individual employee records.

Example Usage:

Creates an instance of Employee, initializing it with the name, employee ID, hourly rate, hours per day, and days worked. The instance then displays the employee's total pay and other details.

Problem Statement: There are 10 men, who are fat, their weights range from 90 kgs to 150kgs. The ideal weight is 88kgs. Now, if some one is between 90-93. he has to run 3 kms, a day, and for every people between 93-96, the distance is multiplied by 2. So, you have to create a base class, and display the range of weight and the workout each ought to do for a day. Now create another class, this class will inherit the parent class methods, in this class, you will get the name, and weight of the person, and then you will find the range of weight that the person falls, in, and then using the methods in base class, you will find the workout requirement, and will display the name, the weight and the workout run that this man ought to do, as always, give the explanation for your actions using html tags

Example 2:WeightLoss Program

      
          class WorkoutRequirement:
    def __init__(self):
        # Define the workout requirement ranges and multipliers
        self.ranges = [(90, 93), (93, 96), (96, 99), (99, 102), (102, 105)]
        self.multipliers = [1, 2, 3, 4, 5]  # Corresponding multipliers for each range

    def calculate_workout(self, weight):
        base_distance = 3  # Base distance in kilometers
        for i, weight_range in enumerate(self.ranges):
            if weight_range[0] <= weight < weight_range[1]:
                return base_distance * self.multipliers[i]
        return 0  # For weights outside the specified ranges          

Example 2-cont

      
          
class Person(WorkoutRequirement):
    def __init__(self, name, weight):
        super().__init__()
        self.name = name
        self.weight = weight

    def display_workout_plan(self):
        workout_distance = self.calculate_workout(self.weight)
        print(f"{self.name} weighs {self.weight}kg and needs to run {workout_distance}km a day.")

# Example creator:Pycent.com
persons = [
    Person("John", 91),
    Person("David", 95),
    Person("Stephen", 102)  # Example where no workout is specified in the range
]

for person in persons:
    person.display_workout_plan()
          

Explanation of the Workout Plan Code

Base Class (WorkoutRequirement):

Purpose: Defines the basic structure and functionality for calculating the workout requirements based on weight ranges and associated distance multipliers.

Method (calculate_workout): Determines the workout distance based on the weight of an individual. It checks the weight against defined ranges and applies a corresponding multiplier to the base distance of 3 km.

Derived Class (Person):

Purpose: Extends the WorkoutRequirement class by incorporating personal details such as name and weight, and utilizes inherited methods to determine and display individual workout plans.

Method (display_workout_plan): This method utilizes the inherited calculate_workout method to find out the necessary workout distance and then prints out the person’s name, weight, and required daily workout.

Practical Application:

This structure allows for easily adding or modifying workout rules based on weight without changing the logic for individual person management, adhering to the principles of scalability and maintainability in OOP.