Pseudocode Task

Hint: This pseudocode defines a Robot class with methods to move and report status. Two robot instances are created and manipulated.

CLASS Robot:
    DEFINE CONSTRUCTOR(nameParam, batteryParam):
        SET self.robotName TO nameParam
        SET self.batteryLevel TO batteryParam
        SET self.xPosition TO 0
        SET self.yPosition TO 0
 
    DEFINE METHOD move(direction, distance):
        IF direction IS "forward" THEN
            SET self.yPosition TO self.yPosition + distance
        ELSEIF direction IS "backward" THEN
            SET self.yPosition TO self.yPosition - distance
        ELSEIF direction IS "right" THEN
            SET self.xPosition TO self.xPosition + distance
        ELSEIF direction IS "left" THEN
            SET self.xPosition TO self.xPosition - distance
        ENDIF
        SET self.batteryLevel TO self.batteryLevel - (distance / 5) // assume battery drains with movement
 
    DEFINE METHOD reportStatus():
        PRINT "Robot Name: ", self.robotName
        PRINT "Position: (", self.xPosition, ", ", self.yPosition, ")"
        PRINT "Battery: ", self.batteryLevel, "%"
 
CREATE bot1 = NEW Robot("RoboUnit-Alpha", 100)
CREATE bot2 = NEW Robot("HelperBot-Beta", 90)
 
CALL bot1.move("forward", 10)
CALL bot1.move("right", 5)
CALL bot1.reportStatus()
 
CALL bot2.move("left", 7)
CALL bot2.reportStatus()
 
// Example of directly changing an attribute:
SET bot2.batteryLevel TO bot2.batteryLevel + 20 // recharge battery
CALL bot2.reportStatus()