Java Strings
Learning Goals
- How do we make Strings and how do they work in memory?
- How do we perform common operations with Strings?
Assignments Goals
Climb The Stairs
For all these maps:
climb-the-stairs__1.jev
climb-the-stairs__2.jev
climb-the-stairs__3.jev
climb-the-stairs__4.jev
climb-the-stairs__5.jev
climb-the-stairs__6.jev
climb-the-stairs__7.jev (GRADE BOOK)
climb-the-stairs__8.jev (GRADE BOOK)
climb-the-stairs__9.jev
**( Only if you want to get that ‘A’)
Pascal’s Triangle
Pascals Triangle presents a simple formula for expanding binomials. If you think a little bit about how Pascal’s Triangle determines each term, you should see that a recursive method is used!
The animation below demonstrates the recursive nature of Pascal’s Triangle.
Objective: to employ recursion to be able to print out an entire line of Pascal’s Triangle . Look at the animation, getting a particular term in a line is inherently recursive. This class should throw an ArithmeticException if you attempt to calculate an invalid Term. (quick example of how to throw an Exception)
Hint: You only need to use recusion to get the term of the expansion.
Part II
Now that you can print out an entire line of Pascal’s Triangle. Print out the entire triangle up to some degree ‘n’.
Description: This method prints the numbers from num down to and including on new lines
Method Call | output |
countDown(5) | 5 4 3 2 1 0 |
countDown(3) | 3 2 1 0 |
Description: This method prints each letter of String s on new lines in reverse order.
Method Call | output |
printRev(“abcdef”) | a b c d e f |
printRev(“abc”) | a b c |
int sumLessthan(int n)
Description: This method returns the sum of all positive integers less than or equal to n
Method Call | output |
sumLessThan(4) | 10 (4+3+2+1) |
sumLessThan( 5 ) | 15 ( 5 + 4 + 3 + 2 + 1) |
int sumLessthan(int n)
Description: This method returns the sum of all positive integers less than or equal to n
Method Call | output |
sumLessThan(4) | 10 (4+3+2+1) |
sumLessThan( 5 ) | 15 ( 5 + 4 + 3 + 2 + 1) |
double average( int[] nums, int index)
Description: This method returns the average of all the elements in nums. The parameter ‘idnex’ is used to keep track of how far along you have gone in the array.
Method Call | output |
average({3,2,1}, 0) | 2 |
average({3,2,2}, 0) | 2.333333 |
Recur
bunnyEars2() (try to figure out what goes where the question marks are)
1 2 3 4 5 6 |
if(bunnies == 0) return 0; if(bunnies % 2 == 0) return 3 +bunnyEars2(?????); return 2 +bunnyEars2( ????? ); |
Recursion problems (bunny ears is a good, straight forward one to start with)
Two Friends Meet
In the prior assignment (#2b), you were asked to go around the inner lake as shown below. We are going to add 1 new requirement to this
What is new this time?
recangular-lake.jev
recangular-lake-if2.jev
Scroll down for a hint about how to handle if test #1 for this map.
A closerlook at if test #1 (how to get around that first if test)
rectangular-lake-bumps1.jev
recangular-lake-bump3A.jev
recangular-lake-bump3B.jev ( NOT BEING GRADED, SKIP THIS)
walk-the-lake-jacks-map.jev
Write an infinite loop (1 while loop). You may NOT use isWater()
Objective: Your goal is get your jeroo onto the right side of the island. Note that the red areas are nets. You must toss() a flower onto the net before you can go on the net.. You will need the following island file .
The first time that we did this our code looked like this .
|
#1)However, we want to create the following custom method custom_method .
#2) Then our “main Section” code should be changed to: