THIS NEEDS TO BE DONE IN C#!! The Tourtise and The Hair In this lab, we will be simulating the classic race of the tourtise and the hare. The race will take place on two paths of 70 tiles, which spans from left to right. The path will have two lanes, one for each animal. The path will be represented as an array of 70 characters, where each character will be the following: · A dash(i.e, “-“), which represents an empty tile. · An “h”, which represents the hare on the hare lane. · A “t”, which represents the tourtise on the tortise lane. All tiles will be “empty” (i.e. set to the dash) with the exception of the tiles that are occupied by the animals. As the animals move, the previous tile the animal was on will be set to empty, and the new tile will be changed to either “h” or “t”. Tile 70 will be the finishing tile, and the first animal to that tile will be declared the winner of the race. We will use randomization to determine how far each animal will move. Since this race will be hilly, there is a chance that both animals slip, meaning that they will be pushed backwards on the race. The following table describes how each animal moves: To generate the move made, the program will generate a random number from 1 to 10. The number generated will determine the move made. Take the torotise for example. If the number is 1 – 5(50% of the possible range), then the torotise will perform a “dash” move, 6 and 7 will perform a slip, and 8 – 10 will perform a walk. The hare’s movements will be determined in a similar fashion. Additionally, to see the moves in real time, the program will pause for 1 second between each move. To do so, use C#’s sleep function, which is typed as “Thread.Sleep(1000)”. Additionally, the console window can be cleared using “Console.Clear()” so that the previous positions are erased from the screen(giving the impression of the race being “animated”). To design your program, you are going to apply inheritance and polymorphic techniques. For the animals, you are going to have three classes: a RaceAnimal class which serves as a base class, and two additional classes, one for each animal, that serve as derived classes. The RaceAnimal class will be abstract and define attributes/methods for managing the track. The RaceAnimal class will have an abstract method called Move, which must be overridden in the derived classes and defined how that specific animal moves. Additionally, you will also define a Race class, which simulates the overall race. The main function will then call race.simulate() to start the race. RaceAnimal Attribute Descriptions: · track – stores the current track. The symbol is printed in the element for the current position of the animal. Every other element should have a dash(‘-‘). · symbol – stores the symbol used to represent the animal on the track. · position – stores the current position of the animal on the track. Is the index of the element in the track array. Must only be a number between 0 and 69. · name – stores the name of the animal.     RaceAnimal Method Descriptions: · constructor – sets the track up by printing the dashes and animal symbol. The name and symbol of the animal should be passed in as parameters. The derived classes will pass in the name and symbol to the based class using the example listed in Appendix A. · ToString – Overrides the ToString method in C#. When called, should output the animals track in the Race. Will be used in the Race class for output. Returns a string built from the track array. · ChangePos – A utility method that takes in the number of steps to move and applies it to the track. Can move the animal backwards and forwards. This should check the bounds of the track to ensure the move is in bounds. · Move – An abstrat method that MUST ONLY be defined in the derived classes. When called, moves the animal along the track. Will be overridden for each of the animals.   UML Tables for Hare and Tortoise Class class Hare: RaceAnimal class Tortoise: RaceAnimal URL Legend Plus(“+”) : public access Dash(“-“): private access Hashtag(“#”): protected access +constructor() overridden Move() +constructor() overridden Move()   Hare and Tourtise Method Descriptions: · constructor – Calls the RaceAnimal method and passes the animal name and symbol to the base class constructor (see Appendix A for an example of how to do this.) Does nothing else….   · Move – Overrides the Move method in RaceAnimal class. Will update the position of the animal based on the charts provided above for each animal type. Calls ChangePos once the move type is determined to change the position of the animal.   Note: These are two separate class definitions, which each inherit from RaceAnimal. Each class’s Move method will be coded based on how the type of animal moves.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

THIS NEEDS TO BE DONE IN C#!!

The Tourtise and The Hair

In this lab, we will be simulating the classic race of the tourtise and the hare. The race will take place on two paths of 70 tiles, which spans from left to right. The path will have two lanes, one for each animal. The path will be represented as an array of 70 characters, where each character will be the following:

· A dash(i.e, “-“), which represents an empty tile.

· An “h”, which represents the hare on the hare lane.

· A “t”, which represents the tourtise on the tortise lane.

All tiles will be “empty” (i.e. set to the dash) with the exception of the tiles that are occupied by the animals. As the animals move, the previous tile the animal was on will be set to empty, and the new tile will be changed to either “h” or “t”. Tile 70 will be the finishing tile, and the first animal to that tile will be declared the winner of the race.

We will use randomization to determine how far each animal will move. Since this race will be hilly, there is a chance that both animals slip, meaning that they will be pushed backwards on the race. The following table describes how each animal moves:

To generate the move made, the program will generate a random number from 1 to 10. The number generated will determine the move made. Take the torotise for example. If the number is 1 – 5(50% of the possible range), then the torotise will perform a “dash” move, 6 and 7 will perform a slip, and 8 – 10 will perform a walk. The hare’s movements will be determined in a similar fashion. Additionally, to see the moves in real time, the program will pause for 1 second between each move. To do so, use C#’s sleep function, which is typed as “Thread.Sleep(1000)”. Additionally, the console window can be cleared using “Console.Clear()” so that the previous positions are erased from the screen(giving the impression of the race being “animated”).

To design your program, you are going to apply inheritance and polymorphic techniques. For the animals, you are going to have three classes: a RaceAnimal class which serves as a base class, and two additional classes, one for each animal, that serve as derived classes. The RaceAnimal class will be abstract and define attributes/methods for managing the track. The RaceAnimal class will have an abstract method called Move, which must be overridden in the derived classes and defined how that specific animal moves. Additionally, you will also define a Race class, which simulates the overall race. The main function will then call race.simulate() to start the race.

RaceAnimal Attribute Descriptions:

· track – stores the current track. The symbol is printed in the element for the current position of the animal. Every other element should have a dash(‘-‘).

· symbol – stores the symbol used to represent the animal on the track.

· position – stores the current position of the animal on the track. Is the index of the element in the track array. Must only be a number between 0 and 69.

· name – stores the name of the animal.

 

 

RaceAnimal Method Descriptions:

· constructor – sets the track up by printing the dashes and animal symbol. The name and symbol of the animal should be passed in as parameters. The derived classes will pass in the name and symbol to the based class using the example listed in Appendix A.

· ToString – Overrides the ToString method in C#. When called, should output the animals track in the Race. Will be used in the Race class for output. Returns a string built from the track array.

· ChangePos – A utility method that takes in the number of steps to move and applies it to the track. Can move the animal backwards and forwards. This should check the bounds of the track to ensure the move is in bounds.

· Move – An abstrat method that MUST ONLY be defined in the derived classes. When called, moves the animal along the track. Will be overridden for each of the animals.

 

UML Tables for Hare and Tortoise Class

class Hare: RaceAnimal class Tortoise: RaceAnimal URL Legend

<none> <none> Plus(“+”) : public access Dash(“-“): private access Hashtag(“#”): protected access

+constructor()

overridden Move() +constructor() overridden Move()

 

Hare and Tourtise Method Descriptions:

· constructor – Calls the RaceAnimal method and passes the animal name and symbol to the base class constructor (see Appendix A for an example of how to do this.) Does nothing else….

 

· Move – Overrides the Move method in RaceAnimal class. Will update the position of the animal based on the charts provided above for each animal type. Calls ChangePos once the move type is determined to change the position of the animal.

 

Note: These are two separate class definitions, which each inherit from RaceAnimal. Each class’s Move method will be coded based on how the type of animal moves.

 
Sample Output
CIN C:\Users\Chad\source\repos\The Tortoise and the Hare Problem\The Tortoise and the Hare Problem\bin\Debu
Note: This output was generated without "Console.Clear()" to demonstrate the change in position of
the animals. The actual solution should use the clear command to simulate animation.
Output after the race is concluded:
CN Microsoft Visual Studio Debug Console
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*
The Hare Won the Race!
runs* none* non*none*nn* an* non*
*~~*~~*~~*~~*~~*~~
C:\Users\Chad\source\repos\The Tortoise and the Hare Problem\The Tortoise and
oise and the Hare Problem.exe (process 19932) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Option
le when debugging stops.
Press any key to close this window ..
Transcribed Image Text:Sample Output CIN C:\Users\Chad\source\repos\The Tortoise and the Hare Problem\The Tortoise and the Hare Problem\bin\Debu Note: This output was generated without "Console.Clear()" to demonstrate the change in position of the animals. The actual solution should use the clear command to simulate animation. Output after the race is concluded: CN Microsoft Visual Studio Debug Console ~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~* The Hare Won the Race! runs* none* non*none*nn* an* non* *~~*~~*~~*~~*~~*~~ C:\Users\Chad\source\repos\The Tortoise and the Hare Problem\The Tortoise and oise and the Hare Problem.exe (process 19932) exited with code 0. To automatically close the console when debugging stops, enable Tools->Option le when debugging stops. Press any key to close this window ..
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education