Question
You are provided with a file robot.py (see attached file later). This file contains code that implements a very basic Robot object. It has a
You are provided with a file robot.py (see attached file later). This file contains code that implements a very basic Robot object. It has a constructor, getter and setter methods. Take a look at the Robot class and familiarize yourself with those methods.
Your task is to write the main routine that creates a Robot object, prints the initial state of the object, moves the Robot forward some distance, displays the current state of the Robot after moving forward, charges the Robot's battery and then displays the state of the Robot after charging its battery.
# File Name: robot.py
# Purpose: A basic class to represent a robot
import math
class Robot:
# constructor
def __init__(self, level = 3.00):
self.__distanceTraveled = 0
self.__batteryLevel = level
# getters
def getDistanceTraveled(self):
return self.__distanceTraveled
def getBatteryLevel(self):
return self.__batteryLevel
# setters
def charge(self, amount):
self.__batteryLevel += amount def moveForward(self, distance): self.__distanceTraveled = self.__distanceTraveled + distance
self.__batteryLevel = self.__batteryLevel * (1.0 - distance/(distance + 1.0))
# helper methods def getCurrentSpeed(self):
speed = math.pow(self.__batteryLevel, 2.0) * 2.0
return speed
def getEstimatedTimeHome(self):
time = self.__distanceTraveled / self.getCurrentSpeed()
return time
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started