Testing for SubStrings (Due 12 Apr 2004)

This is a modification of the programming assignment 7.4 on page 277 of your book. You can check whether a string is a substring of another string by using the indexOf() method in the String class. Write a program that prompts the user to enter two strings and check whether the first string is a substring of the second. If the first string is a substring of the second string then your program should print out the number of times the first string occurs in the second string. Instead of writing a method to substitute the indexOf() method as suggested in exercise 7.4, use the standard indexOf() method to write this program.

This is what the output will look like in one case:

Enter a string: ab
Enter another string: babacbabdabfab

ab is a substring of babacbabdabfab and occurs 4 times.

This is what the output will look like in another case:
Enter a string: er
Enter another string: reabear

er is not a substring of reabear

The file that you will be turning in will be called SubString.java. You will follow the standard Java coding convention that I have appended below. The file will have a header of the following form:

/*
  File: SubString.java

  Description:

  Student Name:

  Student UT EID:

  Course Name: CS 303E

  Unique Number: 

  TA:

  Date Created:

  Date Last Modified:

*/

Sorting the letters in a String (Due 12 Apr 2004)

This is a modification of the programming assignment 7.9 on page 278 of your book. The user will pass a String through the command line. Your program will print out the sorted String. You will write a method sortString() that will sort the string. The method signature reads:
public static String sortString ( String s )

In the method sortString() you can convert the string into an array of characters. Sort the array of characters using the Selection Sort algorithm discussed in class. Then convert the sorted array of characters to a String and return that String. Remember that characters have integer representations and can be compared using the relational boolean operators just like integers.

The file that you will be turning in will be called SortString.java. You will follow the standard Java coding convention that I have appended below. The file will have a header of the following form:

/*
  File: SortString.java

  Description:

  Student Name:

  Student UT EID:

  Course Name: CS 303E

  Unique Number: 

  TA:

  Date Created:

  Date Last Modified:

*/

You will follow the standard Java Coding Conventions. You can either view the HTML page or download the PDF or Postscript and print it out. There is a modification that I would like to make to the standard coding conventions. Please align the opening and closing braces vertically so that you can easily make out the blocks of code.

Use the turnin program to submit the files SubString.java and SortString.java. The TAs should receive your work by 11 PM, Monday, 12 April 2004.