Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In python please Lab 1 2 B: My dog can do tricks For this lab we are going to create a Dog class. Dog objects
In python please
LabB: My dog can do tricks
For this lab we are going to create a Dog class.
Dog objects have a few attributes, but this time unlike chair objects they can also do some cool things too. Each action is represented by a method. Therefore, for any action our Dog can do or we do to the Dog, we are going to create a method. For example, if you want my Dog to bark, you can create a method to do that in the Dog class and call that method outside of the class once you have created an object
Dog class:
Variables Attributes:
o age # current age of the dog, should be an int
o weight # weight in lbs should be a float
o name # what is the name of the dog, a string
o furColor # color of the dogs furhair a string
o breed # what breed is the dog, a string
Behaviors Methods:
o bark # prints Woof Woof!
o rename # take a string and change the name of the dog
o eat # take a float and add that number to weight
Keep in mind that methods inside of a class will always take the self parameter. This parameter is always automatically passed whenever you call a method from an object. However, some methods must take in more than just the self parameter; in this case, these extra parameters must be passed before the method can be called.
Outside the Dog class, create a new Dog object and prompt the user to input the attributes describing this Dog. Once done, print out all the details about the Dog, as per the sample output.
Next, use the methods you created in the Dog class to have it bark, change the name using the rename method, not the dot operator and feed it
Finally print out all the details about the Dog, the object should have changed because of your calls to the various methods.
Sample output user input in bold:
You are about to create a dog.
How old is the dog:
How much does the dog weigh:
What is the dogs name: Patches
What color is the dog: chocolate
What breed is the dog: lab
Patches is a year old chocolate lab that weighs lbs
Woof! Woof!
Patches is hungry, how much should he eat:
Patches isnt a very good name. What should they be renamed to: Sparky
Sparky is a year old chocolate lab that weighs lbs
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