DEV Community

Cover image for Day 17 of My AI & Data Mastery Journey: From Python to Generative AI
Nitin-bhatt46
Nitin-bhatt46

Posted on

Day 17 of My AI & Data Mastery Journey: From Python to Generative AI

Project Brief: Company Payment System

Scenario (Real-world + Critical Thinking):
You are building a system for a company to manage employees and process payments. Employees can be regular employees or managers.
Payments can be made via CreditCard, UPI, or Cash.
We need to track salary, bonuses, and ensure encapsulation for salary so no one can directly modify it.

Step 1: Classes to Create

Employee (Base class)

Attributes: name (str), __salary (private, int)

Methods:

get_salary() → return salary

set_salary(amount) → add bonus to salary

display() → print employee info

Manager (Subclass of Employee)

Attribute: department

Method: display() → override to include department

Payment Methods (Polymorphism)

Classes: CreditCard, UPI, Cash

Method: pay(amount) → print message like "Paid ₹amount using CreditCard"

Step 2: Tasks for Creation

Create 2 employees (1 regular, 1 manager).

Give them salary and bonus using encapsulation methods.

Process a payment for each using all 3 payment methods.

Print final salaries and payment confirmations.

_Debug Task _

Here’s a buggy code snippet related to salary handling. Your job: fix it without changing the logic, just correct errors:

class Employee:
    def __init__(self, name, salary):
        name = name
        __salary = salary  # Problem here

    def get_salary(self):
        return __salary  # Problem here

    def set_salary(self, amount):
        __salary += amount  # Problem here
Enter fullscreen mode Exit fullscreen mode

Inputs:

Employee name: "Alice"

Salary: 50000

Bonus: 5000

Task:

Debug this code so you can properly get and set salary.

Hint: Think self and private attributes.

✅ Your Goal Today

Creation Task: Build full project with Employee, Manager, and Payment classes, and run payments.

Debug Task: Fix the salary handling snippet above.

Top comments (1)

Collapse
 
nitinbhatt46 profile image
Nitin-bhatt46

ready for any feedback, And creating a community to learn.