Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago