Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions fullstack-cert/python-projects/robot-control-lab/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from abc import ABC, abstractmethod

class Robot(ABC):
@abstractmethod
def move_forward(self):
pass

@abstractmethod
def turn(self, direction):
pass

@abstractmethod
def perform_task(self):
pass

class CleaningRobot(Robot):
def move_forward(self):
print("CleaningRobot moves forward 1 meter.")

def turn(self, direction):
print(f"CleaningRobot turns {direction}.")

def perform_task(self):
print("CleaningRobot vacuums the floor.")

class DeliveryRobot(Robot):
def move_forward(self):
print("DeliveryRobot rolls forward to the destination.")

def turn(self, direction):
print(f"DeliveryRobot turns {direction} to follow the path.")

def perform_task(self):
print("DeliveryRobot delivers a package.")

class SurveillanceRobot(Robot):
def move_forward(self):
print("SurveillanceRobot hovers forward silently.")

def turn(self, direction):
print(f"SurveillanceRobot rotates camera {direction}.")

def perform_task(self):
print("SurveillanceRobot scans the area.")

def operate_robot(robot: Robot):
robot.move_forward()
robot.turn("left")
robot.perform_task()

# Example usage
operate_robot(CleaningRobot())
print()
operate_robot(DeliveryRobot())
print()
operate_robot(SurveillanceRobot())
28 changes: 28 additions & 0 deletions fullstack-cert/python-projects/robot-control-lab/user-stories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
1. Define an abstract base class `Robot`:
- Inherit from Python’s `ABC` (Abstract Base Class).
- Each abstract method should have `@abstractmethod`.

2. Inside the `Robot` class, define three abstract methods:
- `move_forward(self)`: represents basic forward movement.
- `turn(self, direction)`: represents turning in a specified direction.
- `perform_task(self)`: represents the robot's unique behavior.

3. Create a concrete class `CleaningRobot` that inherits from `Robot`:
- Implement `move_forward()` to print movement behavior.
- Implement `turn(direction)` to print the turn direction.
- Implement `perform_task()` to print "vacuuming the floor."

4. Create a concrete class `DeliveryRobot` that inherits from `Robot`:
- Implement `move_forward()` to print movement behavior.
- Implement `turn(direction)` to print turning behavior.
- Implement `perform_task()` to print "delivers a package."

5. Create a concrete class `SurveillanceRobot` that inherits from `Robot`:
- Implement `move_forward()` to simulate silent movement.
- Implement `turn(direction)` to rotate the camera.
- Implement `perform_task()` to scan for intruders.

6. Define a function `operate_robot(robot)` that accepts a `Robot`:
- Call `robot.move_forward()`.
- Call `robot.turn("left")`.
- Call `robot.perform_task()`.