Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Cat Kills 1 mouse a day, and does not reproduce.

Mice have a chance to reproduce as long as required conditions are met. Reproduction only happens when mice are over 1, and 1 of each sex is present.

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

Simulation should generate following output depending on if the population of mice is greater than or equal to 10, or no mice left:

Mice RULE, Cats Drool Mice Population: ## (integer value)

Or

Cats RULE, Mice Drool Cat Weight (in mice): ##.## (double value, 2 decimal places)

Sample session (requires no user input):

Mice RULE, Cats Drool Mice Population: 11
Press any key to continue . . .

Cats RULE, Mice Drool Cat Weight (in mice): 2.03
Press any key to continue . . .

Mice RULE, Cats Drool Mice Population: 10
Press any key to continue . . .

Cats RULE, Mice Drool Cat Weight (in mice): 2.05
Press any key to continue . . .

The program should consist of following files:

1. LastFirstWeek5CatMouse.java (driver program)

Driver main method should be as shown below. Add appropriate code in it to generate simulation output.

import java.util.ArrayList;

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

cat sylvester = new cat();
ArrayList mice = new ArrayList();
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 && mice.size() < 10)
{
for (mouse m:mice)
m.grow();
sylvester.grow();
mouse.mate(mice);
sylvester.eat(mice);
}
}
}

2. Mammal.java

Instance variables: name (string), age (integer), weight (double), isMale (Boolean)

class mammal constructor : (default constructor) Set age to 1.

grow method : Increases age of mammal by 1.

Accessor / mutator methods for each instance variable above, set or return values as appropriate for data type specified.

3. Cat.java (extends Mammal class)

eat method: Receives mouse arraylist as argument.

Randomly removes a mouse from the population 70% of the time and increases cat weight by the chosen mouse weight. Only increase weight if mouse is removed/eaten.

grow method: Set the cat's age to the current age plus 1. (Use accessor/mutator methods.)

4. Mouse.java (extends Mammal class)

class mouse constructor: (default constructor) Randomly choose sex and assign to isMale as appropriate. Set age to 1. Set weight to 1.

grow method: Increase age of mouse by 1 and weight of mouse by 1% of current weight.

mate method: (static method, receive mouse arraylist as argument) Randomly choose 2 mouse objects from arraylist and if the required conditions are met, proceed with mating. Successful mating conditions are: 1 male and 1 female mouse, both mice older than 1 day. If successful mating happens, randomly create between 0-4 mice and append to arraylist received as argument.

Java, Programming

  • Category:- Java
  • Reference No.:- M91611599
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As