Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want it in java please!! Application: Write a program to predict population growth. Let's assume we have a flock of ducks and we want

I want it in java please!!

image text in transcribedimage text in transcribed

Application: Write a program to predict population growth. Let's assume we have a flock of ducks and we want to calculate how fast the flock is growing. The complication is that the flock has been attacked by an aggressive deadly foot fungus. Fortunately, we have discovered that putting boots on the ducks protects them from the fungus. We want to explore how effective the boots are by computing how many ducks you have after a given number of years, with and without duck boots. Let the user ask as many questions as they want until they choose to quit. Calculations: Use the following formula to calculate how many ducks you have at the end of each month: Blew = Bold + Boldog where: Bnew = the number of ducks at the end of the month Bold = the number of ducks at the beginning of the month g = the growth rate The growth rate represents how fast the flock is multiplying, as a percentage of the current population. The growth rate is computed as follows: g=b-d where: b = birth rate (percentage of baby ducks per duck per month) d=death rate (percentage of dead ducks per duck per month), A birth rate of 0.10 means that the number of baby ducks is 10% of the number of ducks. Notice that the birth rate and death rate are percentages of the current population, so the number of new babies born or the number of deaths each month increases as the population grows. To consider the effect of the foot fungus and the duck boots, we will also use the following variation to the basic formula. Separate the ducks into two groups: those that have boots and those that don't. To compute the population of the ducks in the presence of the fungus, use the following instead... g=b-(d + f) where: b = birth rate (percentage of baby ducks per duck per month) d= standard death rate (percentage of dead ducks per duck per month), f=death rate from the foot fungus The death rate will be two different numbers for the two groups: fA = fungus death rate for ducks with boots fB = fungus death rate for ducks without boots To compute how fast the duck population is growing, repeat these calculations for however many years are necessary. Compute two sets of results: the population without the fungus, and the population with the fungus. You must use double precision variables to do the calculations, but the current population (the number of ducks) at the end of each month must be rounded to the nearest integer. (No fractional ducks; too messy.) The integer result must be used as the starting population for the next month. Input and Output: First, ask the user to enter the birth rate per month. Ask the user to enter these values only once, then use them for all calculations. (The birth rate is a factor of the prospective habitat, and the user will examine only one habitat with each execution of the program.) Afterwards, for each calculation, ask the user to enter the following: the initial population (how many ducks we start with), the standard death rate per month (without the fungus), the fungal death rate per month for ducks with boots, the fungal death rate per month for ducks without boots, the percentage of ducks with boots. The program also needs to know the length of time (the number of months), and then computes the final size of the population (the number of ducks) with the fungus and without the fungus (two numbers). After displaying the results, then ask the user if they want to do another calculation or stop the program. If they choose to do it again, then ask for all the necessary information (except the birth rate). To get more practice with loops, check all user inputs for errors. Display an error message and let the user enter the number again until the user enters a valid value. None of the inputs may be negative numbers. In addition, the death rates must be less than or equal to one. On the other hand, the birth rate may be any non- negative number (positive or zero), The number of months must be positive. The initial population must be greater than or equal to two (for obvious reasons). (To simplify the code, you do not need to check for a non- numeric entry to a request for a number.) Remember to check all option entries ('y' or 'n', 1 or 2) for errors also. For outputs, in addition to displaying the two final results, your program must also give the user the option to have the monthly growth displayed in a table. This table should have at least three columns: the month, the current number of ducks if there were no fungus, and the current number of ducks if there is fungus. The table must be optional so the user can choose to turn it on or off. Make your program easy to use. Start with a brief message identifying what the program does. Afterwards, include enough information in each input prompt so that the user will know what to enter without reading your code. For example, tell the user whether a death rate of 10% should be entered as 0.1 or 10. Label the results thoroughly as well. To make your messages easier to read and understand, display occasional blank lines, especially between the input prompts and the results. Implementation: Use the Scanner class for all input from the keyboard, and "System.out.println" or "...print" for all output to the screen. This will be a console-oriented application. Create only one class, containing the main program and the subprograms. This assignment will not involve defining new classes of objects. You must have one required subprogram that matches the following specifications exactly. Compute (and return the number of ducks after a given length of time (months). The subprogram will also be given the initial population, and three growth rates (without fungus, with fungus for ducks with boots, and with fungus for ducks without boots), as well as a boolean parameter indicating whether or not the user wants the table of mothly results. There will be no input in either of these subprograms, and the only output is the table of intermediate results, if the user chooses to get it. You also must have one subprogram that asks the user to repeat a numeric entry until it is between zero and one inclusive. (Use it to ask for the death rates.) The subprogram will be given the text of the input prompt, and return the final (positive) entry

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago