Question
Instructions: Write a program that uses the Monte Carlo sampling method to estimate the average number of animals observed before spotting one you are tracking
Instructions: Write a program that uses the Monte Carlo sampling method to estimate the average number of animals observed before spotting one you are tracking within a particular ecosystem.
Imagine you've been tasked with observing an animal population in a local ecosystem. Pick the animal you will be watching. One example may be the squirrel population in a local park. There is a variety of squirrels present. You visit the park and count how many squirrels you see before spotting a fox squirrel. Once youve observed this specific type of squirrel, you will note the count as a data entry and start the process over again. For instance if you see two red squirrels, 4 gray squirrels, and then a fox squirrel, you'd record 7 as the count for that trial. A trial stops when a fox squirrel is spotted. Then start your count over again for a new trial. Pretend you've been told there is a 1 in 10 chance of spotting one. After the data is collected, you go back to your workspace, read in the data, and calculate the average count.
Your task today is to write a program to simulate this real world task using the Monte Carlo Method. Think of this program as having two parts:
The first portion will simulate being in the field collecting the raw data for the trials. This data needs to be written to a text file.
For the second part, think about sitting at your desk processing the raw data. The data will be read from the file.
Write all your code within the same class. Use comments within the code to document each section.
- Create a new project called 04.06 Monte Carlo Method in the Mod04 Assignments folder.
- Create a class called AnimalPopulation in the newly-created project folder.
- Write the pseudocode or an outline for the program. Take time to plan your algorithm.
- Prompt the user for the number of trials. Conduct at least 1,000 trials. Ensure the user input meets this criterion.
- Use random numbers to simulate the animals. Determine which number will represent your animal. In the sample, the numbers 19 represent other types of squirrels and 10 represented a fox squirrel.
- For the purpose of this project, choose any ratio for the animal population.
- Conduct the trials to simulate observing your animal. Record the total count for each trial. A trial starts by counting animals and stops when the desired one is spotted.
- Store the counts for each trial in a text file.
- After all the trials have been conducted, process the data. Read back the data for all the trials from the output file. Calculate the total and then determine the average.
- Print the results of the simulation to the screen.
- Use appropriate data types for values. For example, a value used for counting should be an integer and the average a decimal.
Suggestions
- Write this program in stages. Start by planning and then implement. Don't forget to test.
- When first testing the program, start with a small number of trials. This will enable you to double check the results by hand to assure the correct number of integers are written to the file and the average is accurate.
- Use debugging print statements to view different values as your program runs. Remember to comment these out in your final product. This allows you to see the values the computer is using at various stages.
- The text file should show only integers. Each integer represents the total animals counted per trial. If 5 trials are requested, the text file should have only 5 integers.
- In the squirrel sample, if the simulation worked properly, the average should be approximately 10 ( 0.5)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started