Python3 : question about object-oriented programming, Please write program in the template(critter.py),specific information is on the graphs
the missing words in the 4th line are 'To save an attribute, attach it to this self keyword'
# TEXT CODE FOR critter.py
# defining Critter class
class Critter:
# defining constructor method
def __init__(self, species, size, age):
# set attribute species to
parameter attribute
self.species = species
# set attribute size to
parameter size
self.size = size
# set attribute age to parameter
age
self.age = age
# defining can_eat() method
def can_eat(self, prey):
# if size of Critter is greater
then prey return true.
if self.size > prey.size:
return True
# Otherwise return False
else: return False
# defining survive_year() method
def survive_year(self):
# increase the size and age by
1
self.size = self.size + 1
self.age = self.age + 1
# return the current size
return self.size
# defining test() method to test the Critter class
def test():
# creating objects of Critter class
centipede = Critter("centipede", 3, 1)
millipede = Critter("millipede", 3, 1)
spider = Critter("Orb Weaver", 50, 1)
# check whether millipede can eat centipede or not
by calling can_eat() method of critter
print("millipede can " , end = "")
if millipede.can_eat(centipede):
print("eat centipede")
else: print("not eat centipede")
# check whether spider can eat millipede or not
print("spider can " , end = "")
if spider.can_eat(millipede):
print("eat millipede")
else: print("not eat millipede")
# print the age of spider
print("Age of spider is: ", spider.age)
# print the current age of spider by calling
survive_year() method
print("Current age of spider is: ",
spider.survive_year())
# TEXT CODE FOR run.py
# importing test function from critter
from critter import test
# call test() method
test()
SCREENSHOTS
critter.py
run.py
output (after running run.py):
Python3 : question about object-oriented programming, Please write program in the template(critter.py),specific information is on the graphs the missing words in the 4th line are 'To save an attri...
Write a python program using Object Oriented and do the following: 1. create class "cat" with the following properties: name, age (create constructor method: def __init__) 2. create class "adopter" with the following properties: name, phone 3. create class "transaction" with these properties: adopter, cat (above objects) cat1 = "puffy, 2" adopter1 = "Joe, 123" Test your program: Joe adopts puffy. Print: "Per Transaction 1 <joe> has adopted <puffy>" this can only be done with object oriented programming, no way...
This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of the class "Burger" theOrder = Burger() # calling the main method theOrder.main() # And the class is like: class Burger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own...
Java - Object Oriented Programming
Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...
It's my python homework. Not Java. Design type 1: # Creating an object of the class "DeAnzaBurger" theOrder = DeAnzaBurger() # calling the main method theOrder.main() # And the class is like: class DeAnzaBurger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own deign. .... # That...
Write a C++ program for the instructions below. Please
read the instructions carefully and make sure they are followed
correctly.
and please put comment with code!
Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...
Below is the Graph file that
needs to be modified(using Python3) :
#!/usr/bin/python3
# Simple Vertex class
class Vertex:
""" Lightweight vertex structure for a graph.
Vertices can have the following labels:
UNEXPLORED
VISITED
Assuming the element of a vertex is string type
"""
__slots__ = '_element', '_label'
def __init__(self, element, label="UNEXPLORED"):
""" Constructor. """
self._element = element
self._label = label
def element(self):
""" Return element associated with this vertex. """
return self._element
def getLabel(self):
""" Get label assigned to...
Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def __init__(self, make, model, year) Methods in BMW parent class (can leave as method stubs for now): startEngine() -must print "The engine is now on." stopEngine() -must print "The engine is now off." Make another class called ThreeSeries -Must inherit BMW Hint: class ThreeSeries(BMW): -Also passes the three attributes of the parent class and invoke parent Hint: BMW.__init__(self, cruiseControlEnabled, make, model, year) -Constructor must have...
1. Extending the answer from Python HW #7 for question #1, write
the following python code to expand on the Car class. Include the
python code you developed when answering HW #7.
Add class “getter” methods to return the values for model,
color, and MPG
Add class “setter” methods to change the existing values for
model, color, and MPG. The value to be used in the methods will be
passed as an input argument.
Add class method that will calculate...
Python3, write a program, specific information is in the graphs,
I got 7 marks out of 10, you may change my codes to let it gives
correct output,restrications are also on the graph, for loop, in
key word, enumerate,zip,slices, with key word can't be used. All
the information is on the graph, is_shakespeare_play(line) may be a
function given that can check whether is Shakespeare play
Question 2- 10 marks Write the function keep titles short (filename, max charactars) which takes...
This is the question about object-oriend programming(java) please show the detail comment and prefect code of each class, Thank you! This question contain 7 parts(questions) Question 1 Create a class a class Cat with the following UML diagram: (the "-" means private , "+" means public) +-----------------------------------+ | Cat | +-----------------------------------+ | - name: String | | - weight: double | +-----------------------------------+ | + Cat(String name, double weight) | | + getName(): String | | + getWeight(): double | |...