Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions