Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 144
Introduction to Computer Science: Multimedia

Michael Goldwasser

Spring 2015

Dept. of Math & Computer Science

Homework Assignment 4

Strings

Due: 11:00am, Thursday, April 9, 2015


Contents:


Overview

Topic: Strings
Related Reading: pp. 234-240 of Ch. 7 of text, Processing tutorial on Strings/Text
Due: 11:00am, Thursday, April 9, 2015

Note that homework assignments should be submitted in class as hard copy (although you are welcome to test your solutions with Processing).


Collaboration Policy

For this assignment, you must work individually.

Please make sure you adhere to the policies on academic integrity in this regard.


Problems to be Submitted (30 points)

Preface: With understanding of the relevant documentation, you should be able to predict the results for these questions, but you may also choose to try some of these out in Processing to determine the outcome.

  1. (10 points)

    Assume that the following variable has been initialized:

    String school = "Saint Louis University";
    Predict the return value of each of the following commands:

    1. school.length()
    2. school.charAt(3)
    3. school.indexOf('s')
    4. school.substring(3,8)
    5. school.substring(15)

  2. (10 points)

    There is an important difference between the functions split and splitTokens, which we illustrate with the following two examples:

    1. split("multimedia", "im")
    2. splitTokens("multimedia", "im")

    Experiment with these two command, determine the result of each, and then explain in your own words why the respective functions split and splitTokens produces such results.

  3. (10 points)

    Assume that the variable birthday is a string that describes a date such as "3/31/15" or "12/9/1906". You cannot assume the number of digits in any part, but you can presume there are precisely two slashes and that if a two digit number is given for the year, that it implictly begins with 20 (i.e., the "15" means "2015").

    Give a code fragment that assumes such a general birthday string and defines three integer variables, month, date, and year with the appropriate values. That is, if the birthday string were "3/31/15" then you should end up with month = 3, date = 31, and year = 2015 but your code must be written a way that works on any such (well-formed) example.


Michael Goldwasser
CSCI 144, Spring 2015
Last modified: Friday, 24 April 2015
Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit