Cat And Mouse

Write a program that simulates the battle between a cat and mice.

Use this class hierarchy:

Cat

· Kills 1 mouse a day

· Does not reproduce

Mice

· Have a chance to reproduce as long as conditions are met

· Reproduction only happens when mice are over 1 and 1 of each sex is present

Simulation Control

· Simulation continues as long as population is greater than 1 and less than 10

Driver main method should be as shown below: (replacing comment with missing piece)

import java.util.ArrayList;

public class LastFirstWeek5CatMouse
{
public static void main(String [] args)
{

cat sylvester = new cat();
ArrayList<mouse> mice = new ArrayList<mouse>();
mice.add(new mouse());
mice.add(new mouse());
mice.add(new mouse());
mice.get(0).setSex(true);
mice.get(1).setSex(false);
mice.get(2).setSex(false);

while (mice.size() >1

Leave a Reply

Your email address will not be published. Required fields are marked *