Compsci 100e, Fall 2009, In-Class Exercise 2 / Prelab 2

Group members: name and NetID for each (max 3/group)

___________________     ___________________


___________________
Snarf classwork/02_Basics to begin.
  1. Complete the estimate method in Sqrt and add code in your main method to print out the estimate of the square root of c with a tolerance of EPSILON.

  2. What parameter to the estimate method most directly affects the time it takes to run?
    
    
    
    
  3. Complete the runTrials method in Gambler class.

  4. What parameter to the runTrials method most directly affects the time it takes to run?

  5. Suppose that you have a shuffled deck of cards and you turn them up face up, one by one.
    1. How many cards will you turn up until you see one of each suit?
      
      
      
    2. How many cards will you turn up until you see one of each value?
      
      
      
  6. Problem 1.4.35 from Sedgewick & Wayne: Suppose that people enter an empty room until a pair of people share a birthday. On average, how many people will have to enter before there is a match? Assume birthdays to be uniformly distrubuted through out a regular (i.e. non-leap) year.

    In the program Birthday.java, write a method howMany that returns the average number of people that need to be in a room before 2 people have the same birthday. Assume birthdays to be random integers between 0 and 364.

    
    
    
  7. Problem 1.4.31 from Sedgewick & Wayne: A drunkard begins walking aimlessly, starting at a lamp post. At each time step, the drunkard forgets where he or she is, and takes one step at random, either north, east, south, or west, with probability 25%. How far will the drunkard be from the lamp post after N steps?
    
    
    
  8. Write a program RandomWalker.java that takes an integer, N, as input from the user and simulates the motion of a random walker for N steps. After each step, print the location of the random walker, treating the lamp post as the origin (0, 0). Also, print the square of the distance from the origin.
    
    
    
    
    
    
    
  9. Why is the following quotation true?
    A drunk man will find his way home, but a drunk bird may get lost forever

    - Shizuo Kakutani

Submitting

Submit under assignment name class-0902.