Fall 2012, The College of Saint Rose

Lecture 22: More Methods
Date: Tuesday, November 27

Agenda

• Announcements
• For those taking CSC 252 next semester: keep your textbook!
• Final Project continues
• submit design documents
• get to work on the coding
• Exam 2 recap
• More methods
• passing multiple parameters
• In-class exercise

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.

• Gaddis Find the Error Exercise 1, p. 287 (2 points)
• Gaddis Find the Error Exercise 2, p. 287 (2 points)
• Gaddis Algorithm Workbench Exercise 1, p. 287 (2 points)
• Gaddis Algorithm Workbench Exercise 3, p. 288 (2 points)
• Gaddis Algorithm Workbench Exercise 4, p. 288 (2 points)

Examples