Computer Science 202
Introduction to Programming
Fall 2012, The College of Saint Rose
Agenda
We will practice writing a method by modifying the MonteCarloPi example from a few weeks ago. We will make this modification:
Create a method called estimatePi that takes a parameter of the number of points to use for the approximation as its parameter, and which performs the random point generation algorithm and reports its approximation of pi. Then modify the main method so it calls this new method at an appropriate time.
Your new version of the program should have a main method that reads in the number of points from the Scanner, then calls your new estimatePi method. Note that you will need to decide which variables are ones needed by main and which are needed by estimatePi. Information that exists in main which is needed by estimatePi should be passed as parameters (in this case, only the number of points).
Submit just the updated MonteCarloPi.java file in Blackboard under the "Lecture Assignment Submissions" category to the "Lecture 22 In-Class Exercise" item. This will earn you 5 lecture assignment points.
Due at the start of class, Thursday, November 29.
Please submit answers to these questions in Blackboard by the start of class. We will discuss these questions at the start of class, so no late submissions are accepted.
Note: you may need to look back in the chapter for some of the terminology answers I have not emphasized in class.
Examples