Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Task Description

Write a program that allows the user to interact with a console menu to list, breed two rabbytes, and simulate the passage of time.

Requirement: to represent the rabbytes, you must create and use at least one class in your program. This holds for the next tasks.

Write your program from scratch, without reusing previous rabbyte work. There's almost nothing in common. This holds for the next tasks.

Main menu

The program prompt of the main menu looks like:

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

If the user inputs 1, 2, 3 or 0, it runs the corresponding function.

Assume that a correct index is input in the main menu.

Initial Rabbit population

At the beginning of the program, initialise the rabbit population as shown in the table below.

Each rabbit has an ID, a sex (male or female), an age, two parents (they may be unknown). Female rabbytes can be pregnant.

You may need to store additional information of your choosing to write the program.

1. List Rabbytes

Upon inputting 1, the program will then print a table of all rabbytes.

At the beginning of the execution of the program, the table is as shown below.

====

=====

=====

=====

=====

==========

ID

Sex

Age

Dad

Mom

Pregnant

====

=====

=====

=====

=====

==========

0  M           0                No


1  F          1                No

2  M           2                No

3  F           3                No

4  M          4                No

5  F           5                No

6  M           6                No

====  =====  =====  =====  =====  ==========

If the dad or the mom of a rabbit is known, their ID is shown in the corresponding column.

Use the module tabulate to print the list of rabbytes in the expected format.

2. Breed a Rabbit

Upon inputting 2, the program will then ask the user for two rabbytes, who will then be bred. See example below.

Which rabbytes do you want to breed?

First parent:

1

Second parent:

2

Assume the user will input two integers.

A certain number of checks are performed to ensure that the breeding is possible:

1.   Each input must be a rabbit ID. Otherwise, Rabbit not found. Try again. is printed, and the parent is asked for again. See example 1.

2.   If it is a valid rabbit, other checks are performed, in this order:

1.   If the age of the rabbit is 0, the error is Rabbit too young..

2.   When the second parent is input, if the sex of both parents is the

same, then the error is Rabbit cannot be male., or Rabbit cannot be female..

3.   If the rabbit is already pregnant, the error is Rabbit cannot be pregnant..

Multiple errors are given on the same line if there are multiple errors with the input. See example 2.

Assume menu option 2 is used only if there is valid pair of rabbytes that can breed.

Once a valid pair of rabbytes is given, the female one becomes pregnant. See example 2.

3. Wait 1 year

Upon inputting 3, the program will then age all rabbytes by 1 year, and all pregnant rabbytes will give birth to a new 0-year old kitten.

Kittens are born in the order of their mother's ID (smallest first). The ID of a kitten is the smallest non-negative integer currently not-assigned to another rabbit.

The sex of a newborn kitten is male if the ID of the father is smaller than the ID of the mother, female otherwise.

See example 2.

Examples

User inputs are in bold font below.

Example 1

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

2

Which rabbytes do you want to breed?

First parent:

-1

Rabbit not found. Try again.

First parent:

1

Second parent:

10

Rabbit not found. Try again.

Second parent:

2

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

1

====

=====

=====

=====

=====

==========

ID

Sex

Age

Dad

Mom

Pregnant

====

=====

=====

=====

=====

==========

0  M           0                No

1  F          1               Yes

2  M           2                No

3  F           3                No

4  M          4                No

5  F           5                No

6  M           6                No

====  =====  =====  =====  =====  ==========

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

0

Example 2

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

1

====

=====

=====

=====

=====

==========

ID

Sex

Age

Dad

Mom

Pregnant

====

=====

=====

=====

=====

==========

0  M           0                No

1  F          1                No

2  M           2                No

3  F           3                No

4  M          4                No

5  F           5                No

6  M           6                No

====  =====  =====  =====  =====  ==========

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

2

Which rabbytes do you want to breed?

First parent:

0

Rabbit too young. Try again.

First parent:

1

Second parent:

3

Rabbit cannot be female. Try again.

Second parent:

2

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

1

====  =====  =====  =====  =====  ==========

ID  Sex      Age  Dad    Mom    Pregnant

====  =====  =====  =====  =====  ==========

0  M           0                No

1  F          1               Yes

2  M           2                No

3  F           3                No

4  M          4                No

5  F           5                No

6  M           6                No

====  =====  =====  =====  =====  ==========

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

2

Which rabbytes do you want to breed?

First parent:

2

Second parent:

1

Rabbit cannot be pregnant. Try again.

Second parent:

0

Rabbit too young. Rabbit cannot be male. Try again.

Second parent:

3

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

1

====

=====

=====

=====

=====

==========

ID

Sex

Age

Dad

Mom

Pregnant

====

=====

=====

=====

=====

==========

0  M           0                No

1  F          1               Yes

2  M           2                No

3  F          3               Yes

4  M          4                No

5  F           5                No

6  M           6                No

====  =====  =====  =====  =====  ==========

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

3

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

1

====

=====

=====

=====

=====

==========

ID

Sex

Age

Dad

Mom

Pregnant

====

=====

=====

=====

=====

==========

0  M          1                No

1  F          2                  No

2  M          3                No

3  F           4                No

4  M          5                No

5  F          6                No

6  M           7                No

7  F          0  2      1      No

8  M           0  2      3      No

====  =====  =====  =====  =====  ==========

==================================

Enter your choice:

1. List Rabbytes.

2. Breed a Rabbit.

3. Wait 1 year.

0. Quit.

==================================

0