Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Write a program to predict population growth. For example, let's assume we have a bunny farm and we want to calculate how fast our

image text in transcribed

image text in transcribed

image text in transcribed

Java

Write a program to predict population growth. For example, let's assume we have a bunny farm and we want to calculate how fast our colony of bunnies is growing. First, ask the user for the number of bunnies that the farm can comfortably support. (This is the 'carrying capacity of the farm. Above that number, bunnies start dying from overcrowding.) Then your program will be able answer the following question: How many bunnies will I have after this many months? Ask the user for the information necessary to answer the question. After answering each question, ask the user whether they want to ask another question for that farm (with the same carrying capacity). If they want to ask another question, then ask for all the information again (except for the carrying capacity). When they are done asking questions about that farm, ask the user if they want to try another farm. If they do, then ask them for the carrying capacity and repeat the whole process. Otherwise, stop the program. Calculations: Use the following formula, called the Logistic Model, to calculate how many bunnies you have at the end of each month: Bnew = Bold + g Bold (1 - Bold) where: Pod the actual number of bunnies at the beginning of the month Bold = the relative population of bunnies at the beginning of the month where Bold Pola/N Biew the relative population of bunnies at the end of the month Prew = the actual number of bunnies at the end of the month [notice that Pnew-B...N] N=the carrying capacity; the number of bunnies that the local habitat will support g = the growth rate (bunnies per bunny per month) Notice that the 'P-numbers are actual populations, so they will be integers (no partial bunnies). In contrast, the "B-numbers are ratios of the actual population over the carrying capacity, so they must be real numbers. The 'B'-numbers represent a percentage of the carrying capacity. For example, If the local habitat will support 200 bunnies, and the actual population (P-number) is 50, then the relative population (B-number) is... 50/200 -0.25 (which is the same as 25 percent) Notice that the formula for the new population uses relative population (B-numbers), but the numbers you ask the user to enter and the numbers displayed will be actual populations (P-numbers), so you will have to convert back and forth between the two. The growth rate represents how fast the bunnies are multiplying, as a percentage of the current population. The growth rate is typically computed as follows: 8=bd where: b-birth rate (number of new baby bunnies per bunny per month) d-death rate (number of dead bunnies per bunny per month), Notice that the growth rate is a percentage of each month's population, so the number of new babies each month increases as the population grows. To compute how fast the bunny population is growing, repeat these calculations for however many months are necessary. You MUST use the formula above and repeat the calculations with a loop. You must use double precision variables to do the calculations, but the current population (the number of bunnies) at the end of each month must be rounded to the nearest integer. (No fractional bunnies; too messy.) (Relative population must be a double, and actual population must be an integer.) One warning: the actual population can exceed the carrying capacity - it is NOT a maximum. However, at this point, note that one of the terms in the equation becomes negative and the population will tend to shrink. Input and Output: The program needs the following information from the user: the initial population (how many bunnies we start with), the birth rate, the death rate, and the carrying capacity. 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 bunnies). Check every user input for errors: initial population, carrying capacity, and number of months must be positive numbers. The birth rate must be non-negative (positive or zero). The death rate must be a number between 0 and 1 inclusive (1 and 0 are okay too). Also check every option for a valid entry. For outputs, in addition to displaying the answer to the user's question, your program must also give the user the option to have the monthly growth displayed in a table. This table should have at least two columns: the month and the current number of bunnies. (Use tabs to make the columns line up, or you can use 'printf.) The table must be optional so the user can choose to turn it on or off. If I want to know how many bunnies I have after 1000 months, I don't want to wait while the program displays 1000 lines, but for shorter problems might like to see how the colony is doing month to month. (The Canadians call a group of bunnies a 'fluffle.) 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. Label the results thoroughly as well. To make your messages easier to read and understand, print occasional blank lines, especially between the input prompts and the results. Implementation: 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 at least one subprogram. This subprogram must match the following specifications exactly Compute and return) the number of bunnies after a given length of time. This subprogram will also be given the initial population, the growth rate, and the carrying capacity, as well as a boolean parameter indicating whether or not the user wants the table of monthly results. There will be no user input in this subprogram, and the only output is the table of intermediate results, if the user chooses to get it. You may define other subprograms as you find convenient to simplify the program and reduce code duplication. Program: Follow the guidelines listed in your handout on software engineering standards. Start early and get the program working one piece at a time. For example, start by working on the first question (how many bunnies?) for just one year. Then compute the result for multiple years. Then add the table of daily population growth. Logistic Model Example Carrying Capacity: 100 Initial population: 10 Birth Rate: 60% Death Rate: 10% Growth Rate = Birth - Death = 608 - 10% = 50% = 0.5 Pold = Initial Population = 10 Month 1 : Bold = Pold / Carrying Capacity = 10/100 = 0.1 Bnew = Bold + g X Bold x ( 1 - Bold) = 0.1 + 0.5 X 0.1 X ( 1 - 0.1) = 0.1 + 0.5 X 0.1 X 0.9 = 0.1 + 0.045 = 0.145 Pnew = Round ( Bnew X Carrying Capacity ) = Round ( 0.145 X 100) = Round( 14.5) = 15 Month 2: Pold = Pnew = 15 Bold = Pold / Carrying Capacity = 15 / 100 = 0.15 Bnew = Bold + g X Bold x (1 - Bold) = 0.15 + 0.5 X 0.15 X ( 1 - 0.15 ) = 0.15 + 0.5 X 0.15 X 0.85 = 0.15 + 0.06375 = 0.21375 Pnew = Round( Bnew X Carrying Capacity ) = Round( 0.21375 X 100) = Round( 21.375 ) = 21 The notes above are NOT an example of the output. They give a summary of the calculations. The output will be just the final population. In addition, if user requests a table of the intermediate monthly results, the table could lool like the following... Month Population 010 1 15 21 3 29 4 39 51 75

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

More Books

Students also viewed these Databases questions

Question

Why is repatriation orientation and training needed?

Answered: 1 week ago