Project 2: Word Games

The goal of this project is put into practice what you have learned about loops, decisions, and String operations.

1. Introduction

In class we saw a program that would test if a string is a palindrome, that is, a word, number, phrase, or sentence that is the same backwards and forwards. If we ignore spaces, punctuation, and capitalization, some interesting palindromes are

We'll now define a few other word games, and we'll implement a program that will test for these things.

Two words (or longer things... if you can think of any) are semordnilap of each other if one is the same as the other backwards. For examples

Two words or phrases are anagrams of each other if they contain all the same letters (with the same frequency). Examples include

A word or(more likely) sentence is a pangram if it contains every letter of the alphabet at least once. Examples include

2. Your task

Your task in this project is write two programs, one that will input a single String from the user and determine whether it is a pangram, and the other that will input two Strings and determine whether they are anagrams or semordnilap of each other. In either case, do not count case (capitalization), spaces, or punctuation.

As before, you should make a new directory for this project in your directory for this course.

Hint: Rather than tackling these entire problems at once, you should find some way to make easier problems of them first. An important part of managing a programming project is to cut it down into smaller, more manageable tasks. For example, the one-String program, first restrict yourself to working only on single words, all lowercase Once you have that working, think about how to change it so that it disregards case; then worry about disregarding punctation, etc.

Hint 2: Don't be afraid of pre-processing these Strings a little. For example, you could take a String and create a new String based on the original but with extraneous information stripped out; then test the new String for the property.

Hint 3: Don't forget those handy String operations we've learned in class. substring and concatenation can work wonders (for example, suppose you want to remove the third letter from a String, to change "aloha" to "aloa"-- how could you use substring and concatenation to do that?), and the indexOf and lastIndexOf operations were mentioned in lab. You also find information on a bunch of other operations here--- that website contains a lot of information that requires knowledge we haven't gotten to yet, but you can still use it to find out about a few other things you can do with Strings. Feel free to ask for help in reading and applying what's on that list.

3. Turn in

When you are all finished and are confident that your program fulfills all the instructions here and is working right, perform the usual turn-in procedure.

Then print the script file.

 
a2ps (the name of the script file)

Then turn in the hard copy in class or put it in my box.

DUE: Friday, Sept 19, at 5:00 PM.


Thomas VanDrunen
Last modified: Fri Sep 12 12:35:29 CDT 2008