CSc 101: Section 12 – More Strings!

In this section, you are going to work using string methods and displaying various strings and numbers to the canvas and various string methods.


Problem 1

Write a sketch named section_12_1. The starter code is provided below. Modify the starter code by implementing the splitAndShow function so that when this sketch is run, it displays a canvas like the one pictured. splitAndShow accepts one parameter, a string representing a name. The function should split the first name and last name and display them on the canvas separately, with two different colors.
void setup () {
  size(300, 200);
  textSize(40);
}

// Write splitAndShow here

void draw () {
  background(100);
  String name = "James Carlson";
  splitAndShowName(name);
}


Problem 2

Write a sketch named section_12_2. The starter code is provided below. Modify the starter code by implementing the drawLastThree function so that when this sketch is run, it displays a canvas like the one pictured. drawLastThree has three parameters: a string, an x-coordinate, and a y-coordinate. This function should display the last three characters of the string at the x and y coordinates.
void setup () {
  size(300, 300);
  textSize(50);
}

// Write drawLastThree here

void draw () {
  background(100);
  String a = "ABCDEFG";
  drawLastThree(a, 20, 75);
  String b = "one-two-three";
  drawLastThree(b, 20, 150);
  String c = "one-two-three-four-five";
  drawLastThree(c, 20, 225);
}


Problem 3

Write a sketch named section_12_3. The starter code is provided below. Modify the starter code by implementing the drawMidThree function so that when this sketch is run, it displays a canvas like the one pictured. drawMidThree has three parameters: a string, an x-coordinate, and a y-coordinate. This function should display the middle three characters of the string at the x and y coordinates.
void setup () {
  size(300, 300);
  textSize(50);
}

// Write drawMidThree here

void draw () {
  background(100);
  String a = "ABCDEFG";
  drawMidThree(a, 20, 75);
  String b = "one-two-three";
  drawMidThree(b, 20, 150);
  String c = "one-two-three-four-five";
  drawMidThree(c, 20, 225);
}


Problem 4

Write a sketch named section_12_4. The starter code is provided below. Modify the starter code by implementing the drawEveryOther function so that when this sketch is run, it displays a canvas like the one pictured. drawEveryThree has three parameters: a string, an x-coordinate, and a y-coordinate. This function should display every-other character in the parameter string at the x and y coordinates.
void setup () {
  size(300, 300);
  textSize(50);
}

// Write drawEveryOther here

void draw () {
  background(100);
  String a = "ABCDEFG";
  drawEveryOther(a, 20, 75);
  String b = "one-two-three";
  drawEveryOther(b, 20, 150);
  String c = "severalWordsTogether";
  drawEveryOther(c, 20, 225);
}


Problem 5

Write a sketch named section_12_5. The starter code is provided below. Modify the starter code by implementing the drawViwelCount function so that when this sketch is run, it displays a canvas like the one pictured. drawVowelCount has three parameters: a string, an x-coordinate, and a y-coordinate. This function should count the number of vowels in the input string, and display the count at the x and y coordinates.
void setup () {
  size(300, 300);
  textSize(50);
}

// Write drawVowelCount here

void draw () {
  background(100);
  String a = "one two three";
  drawVowelCount(a, 20, 75);
  String b = "these are words";
  drawVowelCount(b, 20, 150);
  String c = "love alone is worth the fight";
  drawVowelCount(c, 20, 225);
}



Submit at least 2 solutions to the D2L dropbox