Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hey guys. I\'m looking to get some help with this project. Please don\'t make th

ID: 3659987 • Letter: H

Question

hey guys. I'm looking to get some help with this project. Please don't make the coding difficult to understand, I am trying to get a firmer grasp on this subject. Thank you. Write a class named Car that has the following fields: -yearModel. The yearModel field is an int that holds the car'syear model. -make. The make field references a String object that holdsthe make of the car. -speed. The speed field is an int that holds the car's currentspeed. In addition, the class should have the following constructorand other methods. -Constructor. The constructor should accept the car's yearmodel and make as arguments. These values should be assigned to theobject's yearModel and make fields. The constructor should alsoassign 0 to the speed field. -Accessors. Appropriate accessor methods should get the valuesstored in an object's yearModel, make, and speed fields. -accelerate. The accelerate method should add 5 to the speedfield each time it is called. -brake. The breake method should substract 5 from the speedfield each time it is called. Demonstrate the class in a program that creates a Car object,and then calls the accelerate method five times. After each call tothe accelerate method, get the current speed of the car and displayit. Then call the brake method five times. After each call to thebrake method, get the current speed of the car and displayit.

Explanation / Answer

# declare a class class Bird: """ This Bird class represents a Bird, it has a name, a color, a size, and an x,y,z position. This is a doc string for the class. It's always good to include doc strings for classes and class methods. """ def __init__(self, name, color, size): """ This __init__ method is called when an instance of a Bird is constructed. Pass the name, color, and size. """ self.name = name self.color = color self.size = size self.x = 0 self.y = 0 self.z = 0 def flyToLocation(self, x, y, z): """ Update the x,y,z position of the bird. """ self.x = x self.y = y self.z = z # If this module is being run directly, create an instance of a Bird, and test out its constructor and it's methods. if __name__ == '__main__': fred = Bird('fred', 'red', 2.3) # instantiate a red, 2.3 kg bird named 'fred', # and assign it to a variable called fred. fred.flyToLocation(34, 29, 16) # have fred fly to a location specified by x, y, z coordinates print "fred's info.." print "name: %s" % fred.name print "color: %s" % fred.color print "location: %d, %d, %d" % (fred.x, fred.y, fred.z) Here's what happens when I run this program from a Linux command line, like this: rmayes$ python bird.py fred's info.. name: fred color: red location: 34, 29, 16 Here's what happens when I access 'help' on my class: rmayes$ python Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import bird >>> help(bird) Help on module bird: NAME bird FILE /Users/rmayes/bird.py CLASSES Bird class Bird | This Bird class represents a Bird, it has a name, a color, a size, | and an x,y,z position. This is a doc string for the class. It's | always good to include doc strings for classes and class methods. | | Methods defined here: | | __init__(self, name, color, size) | This __init__ method is called when an instance of a Bird is | constructed. Pass the name, color, and size. | | flyToLocation(self, x, y, z) | Update the x,y,z position of the bird.