Further Field Methods

Whilst we have created a class that can be used to represent a field it needs further functionality to actually be useful to us. We need to be able to:

  • Report the contents of the field
  • Report the needs of the field (in terms of light, water and food)
  • Grow the contents of the field (based on given amounts of light, water and food)

An updated class diagram for our field would be:

updated class diagram

Field reports

The two reporting methods are going to enable us to be able to "see" what is in the field and also work out what we need to provide the field so that it can grow successfully.

The video below demonstrates how to add these methods:


Task 12

Use the above video to help you add the reporting methods to the field class.


Grow method

The final method that our crop requires is one to grow all of the crops and animals based on the available quantities of light, water and food.

The video below demonstrates how to add this method:


Task 13

Use the above video to help you add the grow method to the field class.


Managing the field

We now have a reasonable class that we can use to represent a field. We can add crops and animals to instances of this class and grow them over a period of time. When we are ready we can remove these crops and animals (and send them off to market).

In the next section we are going to complete our field simulation by adding the necessary functions to produce a management menu.