After a dreadful month of suffering with endless problems, I have completed String 2. I left class on the verge of crying because I had half a problem to fix until I was done, but I had to wait to come home before completing it. It took a while, the last problem, but was definitely worth it once I saw the green check with the star.
Here is my last problem:
----------------------------------------------------------------------------------------------------------------------------------
Given a string and a non-empty word string, return a version of the original String where all chars have been replaced by pluses ("+"), except for appearances of the word string which are preserved unchanged.
public String plusOut(String str, String word) {
String abc = new String("");
// create a new string.
int i= 0;
while (i<str.length())
// as long as we don't exceed the string length,
{
if (str.substring(i).startsWith(word))
{
abc+=word;
i+=word.length();
// when we see the word, we want to add the word to our new string abc. then, make i skip to
// the next letter after the end of the word.
}
else
{
abc+="+";
i++;
// if we're not looking at the word, then simply replace every letter with a +, and increment i by
// one so that it looks at the next letter.
}
}
return abc;
// return our modified string.
}
----------------------------------------------------------------------------------------------------------------------------------
It was very enjoyable to work on Level 2. Although at times the problems frustrated me, it made me learn a lot. I constantly learned new methods (as you saw above), and new ways of thinking. New logic. I am starting to develop the sense of thinking in code.
From here, I do not know where I will go. I will either work on some level 2 things, like warmup 2, or Logic 2, or even maybe AP CS 1 if Mr. Daly thinks that I have a high enough level to work on those. I don't think I will start Level 3, because it is more complicated and I won't have access to Mr. Daly's help over the summer. It all depends on what I decide with Mr. Daly next class.
Either way, I am presenting in 2 weeks time.
I'm very excited !
No comments:
Post a Comment