Explore BrainMass
Share

Explore BrainMass

    Design a Program that Models a Worm's Behavior

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Design a program using pseudocode that models the worm's behavior in the following scenario:

    A worm is moving toward an apple. Each time it moves, the worm cuts the distance between itself and the apple by its own body length until the worm is close enough to enter the apple. The worm can enter the apple when it is within a body length of the apple.

    © BrainMass Inc. brainmass.com October 9, 2019, 9:14 pm ad1c9bdddf
    https://brainmass.com/computer-science/control-structures/design-program-models-worms-behavior-178250

    Solution Preview

    I used the Object-Oriented Design (OOD) for the behavior of the worm. Defining a class Worm, it has two arguments: the length of the worm itself and the distance from the apple. It also has two behaviors: move and enter. Here is the pseudocode with comments.

    class Worm { // Define the class of Worm
    var length; // Define the variable length to be the length of the worm
    var distance; // Define ...

    Solution Summary

    This solution provides guidelines on designing a program using pseudocode to depict a worm's movement.

    $2.19