Question: Ex 1 : Define a class Farmer with the following specifications: Attributes: name ( private ) : The farmer s name ( default to Unknown

Ex 1: Define a class Farmer with the following specifications:
Attributes:
name (private): The farmers name (default to Unknown).
crop (private): The type of crop the farmer cultivates (default to Wheat).
experience (private): The years of farming experience (default to 0).
Methods:
updateCrop(newCrop): Updates the farmers crop type.
increaseExperience(years): Adds the specified years to the farmers experience.
displayRank(): Displays the farmers rank based on experience:
Sprout (if less than 5 years experience)
Pro Farmer (if less than 10 years experience)
Cultivator (otherwise)
Constructor:
Takes optional parameters for name, crop, and experience. If not provided, set default values as mentioned above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!