Wednesday, January 14, 2015

Wednesday, January 14th

Before getting to work today, I saw Hannah's presentation. She did what I had done last quarter - Greenfoot. To be honest, I was very impressed by her projects. I could clearly see that she had put in a lot of effort, enough to create 3 different games. I thought to myself- how come she had so much time? How did she have enough to create those three games on Greenfoot when I barely had time to create two? But then I figured that she didn't watch all of the Joy of Code videos like I did. She told me that for 6 classes she watched videos - not enough to watch all 33 videos.

After Hannah's project, I went up to the Genius Bar with Tommy (no customers), and worked on the usual, strings and arrays.

The problem:

Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length 0).

comboString("Hello", "hi") → "hiHellohi"
comboString("hi", "Hello") → "hiHellohi"
comboString("aaa", "b") → "baaab"


public String comboString(String a, String b) {
 
  if (a.length() < b.length())
// if a is shorter than b,
  {
    return a +b +a;

// then return short + long + short, or a + b+a
  }

  return b+a+b;
  // if a is not shorter than b, then b will be shorter than a since the strings will always be different lengths.
}

I will be doing my presentation on Tuesday, so on Friday and throughout the weekend I will be working on it.

No comments:

Post a Comment