This is not the document you are looking for? Use the search form below to find more!

Report home > Computer / Internet

instructs

0.00 (0 votes)
Document Description
none
File Details
  • Added: November, 16th 2010
  • Reads: 91
  • Downloads: 0
  • File size: 150.04kb
  • Pages: 3
  • Tags: comp, hi, yo
  • content preview
Submitter
  • Name: Blahz
Embed Code:

Add New Comment




Content Preview
5.01 Assignment Instructions – Coin Flip 
There are three separate programs to write in this assignment.  Take your time and use examples 
in the lesson as models. 
Part 1 
Instructions: Write a program that simulates tossing a coin to determine the frequency of 
heads and tails. 
1.  Create a new project called 5.01 Flip A Coin in the Mod05 
Assignments folder. 
2.  Create the HeadsOrTailsV1 class in the newly created project 
folder. 
3.  Use the random() method to simulate the outcome of flipping a coin. 
4.  Ask the user to enter the number of times the coin will be flipped. 
5.  Use the 5.01 Worksheet to record the number of heads and tails for 10, 100, 1000, 
and 10000 flips of a coin. 
6.  Calculate the average number of heads and tails for each set of trials.  (Do this with a 
calculator, not as part of the program). 
7.  What happens as the number of trials increases?  What do you predict for a trial of 
100000 coin tosses? 
Expected Output:  When your program runs correctly, you should see results similar to the 
following screenshot. 
Remember that although this example shows a 50:50 ratio, other outcomes are possible.

Part 2 
Instructions:  Modify your coin toss program to simulate flipping a biased coin (one that 
does not produce a ratio of 50:50). 
1.  Create the HeadsOrTailsV2 class in the 5.01 Flip A Coin 
project in the Mod05 Assignments folder. 
2.  Copy your original program to the newly created class and 
change the name from V1 to V2. 
3.  Decide how biased you want the coin to be and modify the program to produce the 
new results.  Ask the user to enter the number of times the coin will be flipped. 
4.  Use the second part of the 5.01 Worksheet to record the number of heads and tails for 
10, 100, 1000, and 10000 flips of the biased coin.  Be sure to record the Head:Tail 
ratio in the table. 
5.  Calculate the average number of heads and tails for each set of trials.  (Do this with a 
calculator, not as part of the program). 
6.  Submit this worksheet with your programs for this assignment.  What do you predict 
for a trial of 100000 coin tosses? 
Expected Output:  A sample of the output for a biased coin that lands on heads 40% of the time 
and tails 60% of the time is shown below.  Your output will depend on the degree of bias you 
choose. 
Remember that although this example shows a 40:60 ratio, other outcomes are possible.

Part 3 
Instructions:  Write a program to simulate the male to female ratio of a country of your choice. 
1.  Download the 5.01 Male to Female Population Ratios file to the Mod05 Documents 
folder.  Print a copy for your notebook and review the method for determining the 
ratio of males to females in a population. 
2.  Use the CIA World Factbook to locate the Male:Female ratio of the country for the 
population you wish to simulate.  Fill­in the worksheet information at the top of page 
3 of the 5.01 Male to Female Population Ratios worksheet. 
3.  Create a new project called 5.01 Proportion of Males and 
Females in the Mod05 Assignments folder. 
4.  Create the PopulationRatio class in the newly created project 
folder. 
5.  Use an iterative control structure and the random() method 
to simulate determining the male to female ratio of the country 
you chose.  You need to know the percentage of males or 
females in the total population. (Is this similar to Head:Tail 
ratios?) 
6.  As you run your program, record your results in the table on 
the bottom of page 3 of the worksheet. Simulate population 
sizes of 1000, 10000, and 100000. 
7.  Calculate the average number of males and females for each 
trial.  (Do this with a calculator, not as part of the program). 
What happens as the number of trials increases?

Download
instructs

 

 

Your download will begin in a moment.
If it doesn't, click here to try again.

Share instructs to:

Insert your wordpress URL:

example:

http://myblog.wordpress.com/
or
http://myblog.com/

Share instructs as:

From:

To:

Share instructs.

Enter two words as shown below. If you cannot read the words, click the refresh icon.

loading

Share instructs as:

Copy html code above and paste to your web page.

loading