Tuesday, May 12, 2015

Tuesday, May 12th

Today was a good class. I got to class and I realised that I hadn't done the mid quarter report. Mr. Daly wanted me to do it during class, but I preferred to work on CodingBat and have Mr. Daly around to help me if I needed it.  So right after this blog post, I will be posting the mid quarter report.

It was a good class today. It was a particularly good class since I got a problem done completely by myself, without needing help from Mr. Daly at all. To me, this is one of the best possible feelings in this class. I have 25 stars on CodingBat, and now only 4 problems to complete. I have more than enough time to finish level 2.

In honour of my life accomplishment, I'll be showing the problem that I completed alone today.
Here it is:

----------------------------------------------------------------------------------------------------------------------------------

Given two strings, return true if either of the strings appears at the very end of the other string, ignoring upper/lower case differences (in other words, the computation should not be "case sensitive"). Note: str.toLowerCase() returns the lowercase version of a string. 

endOther("Hiabc", "abc") → true
endOther("AbC", "HiaBc") → true
endOther("abc", "abXabc") → true




public boolean endOther(String a, String b) {

  String aone = new String (a.toLowerCase());
    
  String bone = new String (b.toLowerCase());
  // convert both strings to only lowercase letters, so that we don't have an issue with whether 
// or not the letters are capitalised or not.
  
  if (aone.equals(bone))
  {
   return true;
// if the two strings are identical, then it does appear at the end, so return true.
  }
  
  if ((a.length()>b.length()) && aone.substring(aone.length()-bone.length()).equals(bone))
  {
   return true;
// if a is longer than b, and b appears in the last few characters of a, then return true.
  }
  
  if ((b.length()>a.length()) && bone.substring(bone.length()-aone.length()).equals(aone))
  {
   return true;
// if b is longer than a, and a appears in the last few characters of b, then return true.
  }
  
  return false;
// if the above conditions are not true and neither string appears at the end of the other, then
// return true;

}

------------------------------------------------------------------------------------------------------------

This is what I have for today. Obviously, I worked on some other problems. I was close to finishing a problem with Mr. Daly towards the end of class, but I had a meeting during break so we couldn't finish it. Soon, I will be done with everything. Looking forward to Thursday afternoon !

No comments:

Post a Comment