Language is python Implement the required classes to complete the farm_sim progr
ID: 3704974 • Letter: L
Question
Language is python
Implement the required classes to complete the farm_sim program.
# Required classes:
# 1. Crop - water, harvest
# 2. Corn (derived from Crop) - water, harvest
# 3. Wheat (derived from Crop) - water, harvest
# 4. Irrigator - irrigate
#
# Details for each class:
# 1. Crop should start each instance at a height of 0
# 2. Corn should grow by 2 each time it is watered. Corn will
# produce an ear when at height 9 or greater. Harvesting will
# return 1 ear or none.
# 3. Wheat should grow by 1 each time it is watered. A head is
# produced when wheat reaches height 5 or greater. Harvesting
# will return 1 head or none.
# 4. The irrigator will allow a starting load to be provided on
# initialization. When watering a field the irrigator should
# proceed plant by plant and only water them if it has any
# load remaining. Each time a plant is watered the load is
# reduced by 1.
Explanation / Answer
here is your code : ------------>>>>>>>>
class Crop():
height = 0;
class Corn(Crop):
def __init__(self):
self.ear = None;
def water():
Crop.height = Crop.height + 2;
if Crop.height >= 9:
self.ear = 1;
def harvest():
return self.ear;
class Wheat(Crop):
def __init__(self):
self.head = None;
def water():
Crop.height = Crop.height + 1;
if Crop.height >= 5:
self.head = 1;
def harvest():
return head;
class Irrigator():
def __init__(self,load):
self.load = load;
self.plant = [];
def addPlant(plant):
self.plant.append(plant);
def irrigate():
for i in range(0,len(self.plant)):
self.plant[i].water();
load = load - 1;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.