Question

In: Computer Science

C# The Zookeepers need a system to keep track of all their animals. They need to...

C#

The Zookeepers need a system to keep track of all their animals. They need to be able to enter all their animals into the system in a way that allows them to identify and locate them. This requires identifying them by species, age and one characteristic unique to their species.

  • There are three cages and the user must input information about the animal in each one. After accepting input for all three cages, the program should output the contents of each cage in a way that exposes all the information about that animal.
  • The program should accept the following species: Lion, Bear, Wolf.
  • Define classes for the Lion, Bear, and Wolf species that all implement the Animal interface. All Animals should have an int field for age and a String field for species. Each species of animal should have its own unique field defined: String maneColour for Lions, int speed for Wolves, and bool isGrizzly for Bears. They should also define two methods:
    • RequestUniqueCharacteristic() which outputs a string asking for a value to store in the specific animal’s unique characteristic and stores it in the appropriate field (maneColour, speed, or isGrizzly)
    • GetDescription() which outputs a short sentence that includes all the animal’s info.
  • Store all the Animals in a list of animals (List<Animal>) and iterate through the list to output all the animals after input is received.

Sample Session

Cage 1
What is the animal’s species? Lion
How old is it? 6
What colour is its mane? Brown

Cage 2
What is the animal’s species? Wolf
How old is it? 9
How fast can it run (in km/h)? 20

Cage 3
What is the animal’s species? Bear
How old is it? 12
Is it a grizzly bear (true/false)? No
=====
Cage 1 contains a 6-year-old lion with a brown mane.
Cage 2 contains a 9-year-old wolf that runs 20 km/h.
Cage 3 contains a 12-year-old non-grizzly bear.

Solutions

Expert Solution

Hi

Please find the code below

// Interface Animal
public interface Animal
{
// Properties for age, species with the corresponding datatype
int age { get; set; }
String species { get; set; }
// declaration for methods
void RequestUniqueCharacteristic();
void GetDescription();

}

//Lion class
public class Lions : Animal
{
// implement the properties
public int age { get; set; }
public string species { get ; set ; }
// unique field for lion
public string maneColour { get; set; }
// implement getdescription()
public void GetDescription()
{
Console.WriteLine($" {this.age}-year-old lion with a {this.maneColour} mane.");
}

// implement requestUniqueCharacteristic
void Animal.RequestUniqueCharacteristic()
{
Console.WriteLine("What colour is its mane?");
this.maneColour = Console.ReadLine();
}
}

public class Wolves : Animal
{
// implement the properties
public int age { get; set; }
public string species { get; set; }
// unique field for wolf
public int speed { get; set; }
// implement getdescription()
public void GetDescription()
{
Console.WriteLine($" {this.age}-year-old wolf that runs {this.speed} km/h.");
}
// implement requestUniqueCharacteristic
void Animal.RequestUniqueCharacteristic()
{
Console.WriteLine("How fast can it run (in km/h)?");
this.speed = Convert.ToInt32(Console.ReadLine());
}
}

public class Bears : Animal
{
// implement the properties
public int age { get; set; }
public string species { get; set; }
//unique field for bear
public bool isGrizzly { get; set; }
// implement getdescription()
public void GetDescription()
{
if (this.isGrizzly)
Console.WriteLine($" {this.age}-year-old grizzly bear.");
else
Console.WriteLine($" {this.age}-year-old non-grizzly bear.");
}
// implement requestUniqueCharacteristic
void Animal.RequestUniqueCharacteristic()
{
Console.WriteLine("Is it a grizzly bear (true/false)");
var boolString = (Console.ReadLine());
if (boolString == "true")
this.isGrizzly = true;
else
this.isGrizzly = false;
}
}

// program class
class Program
{
// main function
static void Main(string[] args)
{
// List of Animal
List<Animal> animals = new List<Animal>();
// counter initialise with 1
int i = 1;
// iterate 3 times to take the information for 3 cages as per the requirement mentioned
while (i < 4)
{

Animal animal = null;
// ask for the information of cage
Console.WriteLine($"Enter the information for Cage {i}");
Console.WriteLine("What is the animal’s species?");
var species = Console.ReadLine();
if (species.Trim().ToLower() == "lion")
animal = new Lions();

if (species.Trim().ToLower() == "wolf")
animal = new Wolves();

if (species.Trim().ToLower() == "bear")
animal = new Bears();

animal.species = species;
Console.WriteLine("How old is it? ");
// store the details
animal.age = Convert.ToInt32(Console.ReadLine());
animal.RequestUniqueCharacteristic();
// add the animal in animals list
animals.Add(animal);
// increment the counter
i++;
}

for (i = 0; i < animals.Count(); i++)
{
// diplay the cage index
Console.Write($"Cage {i + 1} contains a");
// call getdescription
animals[i].GetDescription();
}
} }

OUTPUT:

Thanks

Hope it helps!!


Related Solutions

C# The Zookeepers need a system to keep track of all their animals. They need to...
C# The Zookeepers need a system to keep track of all their animals. They need to be able to enter all their animals into the system in a way that allows them to identify and locate them. This requires identifying them by species, age and one characteristic unique to their species. There are three cages and the user must input information about the animal in each one. After accepting input for all three cages, the program should output the contents...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
C++ Modify this to use a separate Boolean member to keep track of whether the queue...
C++ Modify this to use a separate Boolean member to keep track of whether the queue is empty rather than require that one array position remain empty. #include <stdio.h> #include <stdlib.h> #include <limits.h> // A structure to represent a queue struct Queue { int front, rear, size; unsigned capacity; int* array; }; // function to create a queue of given capacity. // It initializes size of queue as 0 struct Queue* createQueue(unsigned capacity) { struct Queue* queue = (struct Queue*)...
How can websites keep track of users? Do they always need to use cookies?
How can websites keep track of users? Do they always need to use cookies?
For ONE day, keep track of all of the electrical devices that you make use of...
For ONE day, keep track of all of the electrical devices that you make use of and for how long. (eg. Microwave oven for 3 minutes; hair dryer for 5 minutes; TV for 90 minutes;...) Track only those devices over which you have direct control and don’t bother about things like home heating and refrigerators that are too challenging to track. Using either a published table of common power ratings (cite your source), or information read off of the device...
A retailer, Continental Palms Retail (CPR), plans to create a database system to keep track of...
A retailer, Continental Palms Retail (CPR), plans to create a database system to keep track of the information about its inventory. CPR has several warehouses across the country. Each warehouse is uniquely named. CPR also wants to record the location, city, state, zip, and space (in cubic meters) of each warehouse. There are several warehouses in any single city. CPR stores its products in the warehouses. A product may be stored in multiple warehouses. A warehouse may store multiple products....
Given the following mission statement: . A group of system administrators must keep track of which...
Given the following mission statement: . A group of system administrators must keep track of which computers are assigned to computer users in the community they support. Currently this is done by hand.. but this is tedious, error prone, and inconvenient. System administrators want to automate this task to ease their workload. Product Vision. The Computer Assignment System (CAS) will keep track of computers, computer users, and assignments of computers to users; answer queries; and produce reports about users, computers,...
Use C++ please You will be building a linked list. Make sure to keep track of...
Use C++ please You will be building a linked list. Make sure to keep track of both the head and tail nodes. (1) Create three files to submit. PlaylistNode.h - Class declaration PlaylistNode.cpp - Class definition main.cpp - main() function Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps. Default constructor (1 pt) Parameterized constructor (1 pt) Public member functions InsertAfter() - Mutator (1 pt)...
Task 2 introduction to software engineering A nursery wants to keep track of all its products,...
Task 2 introduction to software engineering A nursery wants to keep track of all its products, including plants, fountains, garden hardware (wheelbarrow, shovels etc) and also soil and sand which they sell. They buy all stock from the wholesalers. The management wants to know which staff members have been selling what, and from which wholesaler the products were purchased. There are also times when a customer returns a product for a refund, and such information should be available in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT