rwe214_prac2

Upload: calvin-maree

Post on 06-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 rwe214_prac2

    1/3

    CS E214

    Practical 2

    2012

    Complete the following questions from the Exercises section in the textbook, In-

    troduction to Programming in Java. Resources for certain questions, such as code

    libraries you are asked to use and example input and output files which can be used for

    development of your programs can be found on the course website. You have to handin your answers to these questions. In order to keep all the files in one place you have

    to tar your files. A quick tutorial on tar is given below.

    Tar how-to

    We use tar to archive multiple files in one file for convenience.

    For more information on tar see the man pages: man tar

    To create a tar archive: tar cvf archive.tar file1 file2 file3

    To extract the files contained in a tar archive: tar xvf archive.tar

    You must use the format prac.tar for your tar file name.

    Hand-in date: 23:59 Sunday 19 February 2012.

    Marking scheme for practical assignments

    The number of marks awarded to each question is given in square brackets. For each

    question, you will earn a mark of zero if your program does not work correctly for

    at least some of the sample input provided to the marker (no partial credit). If your

    program works correctly for a subset of the sample input, you will earn a subset of the

    available marks. If your program works correctly for all of the sample input, you may

    earn up to the maximum mark, depending on the style and readability of your code.

    The total mark for each practical will be rescaled to count out of 100.If you cannot complete all of the questions in the time you have set aside for the

    practical, it is up to you to optimise your mark by doing the easier questions and skip-

    ping the harder ones. Do not spend more time than you have available: if you do this,

    your performance in other subjects will suffer.

    1

  • 8/2/2019 rwe214_prac2

    2/3

    1 Book 1.3.9 [10]

    Write a program AvgRand that takes an integer N as a command-line argument, usesMath.random() to print N uniform random values between 0 and 1, and then printstheir average value. An example of what your command on the command-line and theprogram output should look like:

    $ java AvgRand 5

    0.23

    0.5

    0.18

    0.84

    0.20

    Average: 0.39

    Note that 5 is the command-line argument. The program output must print each randomnumber on a new line and then print the average. The format should be exactly like

    shown above.

    2 Web 1.3.42 [20]

    Chaos. Write a program to study the following simple model for population growth,

    which might be applied to study fish in a pond, bacteria in a test tube, or any of a host

    of similar situations.

    We suppose that the population ranges from 0 (extinct) to 1 (maximum population

    that can be sustained). If the population at time t is x, the we suppose the population attime t + 1 to be rx(1 x) where the parameter r, sometimes known as the fecundity

    parameter, controls the rate of growth.Start with a small population, say x = 0.01 and study the result of iterating the

    model, for various values of r. For which values of r does the population stabilizeat x = 1 1/r? Can you say anything about the population when r is 3.5? 3.8?5? Biologists model population growth of fish in a pond using the logistic equation.

    Investigate some of its chaotic behavior.

    The fecundity parameter r is between 0 and 4 and x is initially chosen to be between0 and 1. The iterates x settle into a definite pattern. This pattern is constant if r