Computer Science 202
Introduction to Programming
Fall 2013, The College of Saint Rose
Agenda
We will work together to write a program LongShortWords.java to read in the words from a file, and write them to two files: one that contains all words at most 4 characters long, and another that contains all words longer than 4 characters, printed out along with their lengths.
Please submit only the file LongShortWords.java in Submission Box under "InClass23-1" before you leave class.
We will then practice writing a method by modifying the MonteCarloPi example. 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).
Please submit only the file MonteCarloPi.java in Submission Box under "InClass23-2" before you leave class.
Due at the start of class, Thursday, December 5.
Please submit answers to these questions in Submission Box under "LA23" by the start of our next class. We will discuss these questions at the start of class, so no late submissions are accepted. Please be sure that your name is clearly indicated in all submissions.
int input; // input gets a value here somehow, we don't care how int answer; // answer should have the value as described above when we get here
if ((year == 2008) || (year == 2010)) { place = 1; } else if ((year == 2009) || (year == 2011)) { place = 2; } else if (year == 2012) { place = 3; } else if (year == 2004) { place = 4; } else { place = 5; }
Examples