The farmer behaved in such way because the earthworms are very helpful to him in making the soil fertile and also making it loose which helps for good penetration of roots in the soil.so he behaved in that way.
Those students were actually killing earthworms for their pleasure without knowing the usefulness of earthworms.
Earthworm belongs to annelida phylum of animalia.
They are bilaterally symmetric, they are triploblastic, they are segmental fashioned with segments lined up one after the other from head to tail.
Hope this helps you :)