CS 111: Fundamentals of Programming 1

Lab 4

Goals

To work with

Log On and Copy Lab4 folder from course folder to your directory

Do two of the following projects.

Population Growth (modification of programming problem 5 from Chapter 4)

A local biologist needs a program to predict population growth. The inputs would be the initial number of organisms - initial population, the growth rate (a real number greater than 0), the number of hours it takes to achieve this rate - rate period, and a number of hours during which the population grows - growth period. For example, one might start with a initial population of 500 organisms, a growth rate of 2, and a rate period of 6 hours. Assuming that none of the organisms die, this would imply that this population would double in size every 6 hours. Thus, after allowing 6 hours for growth, we would have 1000 organisms, and after 12 hours, we would have 2000 organisms. Write a program that takes these inputs and displays a prdediction of the total population.

You are to write a program with a nice GUI for doing this problem. You should have four input fields, one for the initial population (integer), one for growth rate (a double), one for the rate period (integer), and one for the growth period (integer). Also, there should be an output field for the final population and a button to cause the program to compute and display the final population. Try to make the GUI reasonably attractive.

At first, assume that the growth period is a multiple of the rate period. When you have this working, add a feature to you program so that the growth period is adjusted to be the largest multiple of the rate period that is less than or equal to the growth period given. For example with the example give above, if the user gave a growth period of 20 hours, this would be adjusted on the GUI to be 18 hours.

The starting point for this program is Population in the Lab4 folderYou are to write a program with a nice GUI for doing this problem. You should have two input fields for the two positive numbers, an output field for the greatest common divisor and a button to cause the program to compute and display the greatest common divisor of the inputs. Try to make the GUI reasonably attractive.

Investment (modification of programming problem 10 from Chapter 4)

John has $500 to invest. Sue knows of a mutual fund plan that pays 10% interest, compounded quarterly (that is, every 3 months, the principal is multiplied by the 2.5% and the result is added to the principal). Write a program that will tell John how much money will be in the fund after 20 years. Make the program general: That is, it should take as inputs the interest rate, the initial principal, the number of times the interest is compounded annually (assume a divisor of 12), and the number of years to stay in the fund. The program should compute and display the final value of the principal.

You are to write a program with a nice GUI for doing this problem. You should have four input fields, one for the interest rate (double, like 7.5 for 7.5%), one for the initial principal (double), one for the number of times the interest is compounded annually (integer), and the number of years (integer). You should have an output field for the final principal (double) and a button to cause the program to compute and display the final principal (rounded to cents). Try to make the GUI reasonably attractive.

At first, assume that the number of times to compound is a divisor of 12. When you have this working, add a feature to you program so that the number of times to compound is adjusted to be the largest divisor of 12 less than or equal to the number entered. For example, if the user entered 5, this would be adjusted on the GUI to be 4

The starting point for this program is the project Invest in the Lab4 folder.

Euclid's method for finding the Greatest Common Divisor

Given two positive integers m and n, the greatest common divisor of m and n is the largest positive integer that is a divisor of both m and n.

Here is Euclid's 2300-year-old algorithm for finding the greatest common divisor of two positive integers I and J.
1.Get two positive integers as input.
2.Divide I by J, and call the remainder R.
3.If R is not 0, then reset I to the value of J, reset J to the value of R, and go back to step 2.
4.Print out the answer, which is the value of J.
5.Stop.

You will need to change this rough pseudocode into something closer to Java (while loop probably).

You are to write a program with a nice GUI for doing this problem. You should have two input fields for the two positive numbers, an output field for the greatest common divisor and a button to cause the program to compute and display the greatest common divisor of the inputs. Try to make the GUI reasonably attractive. Once you have the basic program working correctly, add the following features:

Be sure to follow all of our guidelines for programming style.

The starting point is the project GCD in the Lab4 folder.

Turn in your work.

When you have completed all work on this lab, you should turn in a print out of your final programs to me or the lab assistant. Be sure that you have comments with your information at the top of the programs. Part of the grade will be based on style. If you do not have all parts working correctly, add clear comments as to the status of the program.

You should also copy your Lab4 folder into your turnin folder.