## Parameter Practice Lab Worksheet

posted by: Mr. Bergquist
11 October 2011
No Comment

These problems are designed to give you practice using parameters. Get as many as you can done and feel free to skip around. I’ll check these off for effort and expect at least the first three to be done.

- Modify RedundantStars.java to reduce redundancy using parameters.
- Write a method that takes in a person’s current age and prints how old that person will be in the year 2092, like:
**“You will be 85 in 2092.”** - Write a method called countQuarters that takes an int representing a number of cents as a parameter and prints the number of quarter coins represented by that many cents. Don’t count any whole dollars, because those would be given as dollar bills. For example, countQuarters(64) would print
**“2 quarters in 64 cents”**because 64 cents is equivalent to 2 quarters with 14 cents left over. A call of countQuarters(1278) would return 3, because after the 12 dollars are taken out, 3 quarters remain in the 78 cents that are left. - The Leibniz formula for pi states that

Write a method called pi that takes one integer parameter. The parameter should represent how many terms of the sequence to use to approximate pi. The method should print out the approximate value (for pi, not for pi/4!). - Write a method called cal that takes two integer parameters. The first should represent the day a month starts on (one for Sunday, two for Monday, etc…) and the second the last day of that month. Calling the method should print a calendar for that month.Try to do as well as you can with what we have learned. The only thing you wonâ€™t be able to do is get the spacing to be different for 1-digit days and 2-digit days. Your output should look like this for a call on cal(5, 31):
- Write a method called printSquare that takes in two integer parameters, a
*min*and a*max*, and prints the numbers in the range from*min*to*max*inclusive in a square pattern. The square pattern is easier to understand by example than by explanation, so take a look at the sample method calls and their resulting console output in the table below.

Each row of the square is composed of a sequence of numbers that increase by one until*max*is printed, after which the numbers wrap back around in the sequence so the next number printed is the*min*. The sequence then resumes, each number increasing by one, until all numbers in the range are printed. Then the row is finished and the next row begins. The first row begins with min, and the starting number on each subsequent row increases by one until the final row begins with max.You may assume the caller of the method will pass a min and a max parameter such that min <= max.

(Leveraged from Ms Martin’s 2010 Parameters Practice Post)