Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Design a ZOO using coding best practices and object oriented design principle

ID: 3552522 • Letter: 1

Question

1. Design a ZOO using coding best practices and object oriented design principles

The requirement went like this

-Zoo can have different type of animals like Tiger, Bear and Monkey

-They all eat food, like Grain, meat etc

-They sleep, play and eat

-They keep track of their energy level

-They keep track of number of species produced

-when they play they loos energy level like -8 points or something

-when they eat they gain

-when they speak by default they say "Grr", and some animals say differently

-they all need to know what type of food they are eating

-some animals are trainable, bear is trainable

-when they are trainable they can dance

-when the bear dance it says "I'm Dancing

Explanation / Answer

public class animals

{

string animal_name {get; set;}

string food {get; set;}

string actions {get; set;}

int energy_levels {get; set;}

string speak {get; set;}

int trainable_or_not{get; set;} // 0-trainable, 1-nontrainable

void check_energy_levels(animal_name, eating_or_playing);

};



class zoo

{

List<animals> animal = new List<animals>();


// Here I am adding animal input directly.

// We can also have textbox and get users data.

// Eg. animal_name = animal_name_textbox.text

animal.add(new animals {animal_name="bear", food="bamboo", actions="play", energy_level=10, speak="growl", trainable_or_not=0});


animal.add(new animals {animal_name="deer", food="grass", actions="sleep", energy_level=8, speak="moo", trainable_or_not=1});


Console.Writeline("Energy level setting");

Console.writeline("Enter the animal name:");

string animal = Console.Read();

Console.writeline("Enter 0 for playing and 1 for eating:");

string eating_or_playing = Console.Read();

check_energy_levels(animal_name, eating_or_playing);


public void check_energy_levels(string animal_name, int eating_or_playing)

{

for(i=0; i<animal.count; i++)

{

if(animal.animal_name = animal_name)

{

if(eating_or_playing == 0) //playing

{

animal.energy_level = animal.energy_level - 8;

}

else if(eating_or_playing == 1) //eating

{

animal.energy_level = animal.energy_level + 8;

}

}

else

{

Console.WriteLine("Animal does not exist");

}

}

}


}