CSC 171
Homework assignment 3

Fall, 1998

In class:

Playing with Strings

Try a whole lot of things you can do to Strings: concatenating them, converting them to upper or lower case, extracting substrings of them, finding their lengths, printing them to System.out with both print and println, etc. You may use my FunWithStrings application as a starting point.

Renaming Programs

This is strictly quill-pen stuff here. When you create a new Java Application with CodeWarrior, you get a source file named TrivialApplication.java, which defines a class named TrivialApplication. "TrivialApplication" isn't a very good name for a program, especially as the semester goes on and they get less and less trivial, so you'll probably want to rename your program to something more meaningful. Once you've chosen a more sensible name, you'll need to tell CodeWarrior about it by changing the name in three places:
  1. Look at the source code file. One of the first lines should be
    public class Trivial Application {
    
    Replace the word "TrivialApplication" in this line with your more sensible name, e.g. "FunWithStrings"
  2. From the "File" menu, choose "Save As...". Make sure you're saving the file in the correct folder (probably the one that already contains your project file and TrivialApplication.java). Type in your new and more sensible name, followed by ".java", e.g. "FunWithStrings.java". Be careful to spell the name exactly the same way, without adding spaces or changing upper- and lower-case. CodeWarrior doesn't absolutely require that the filename be the same as the classname (plus ".java"), but some Java compilers do, and it'll make your life easier.
  3. In the Project window, press the "Target Settings" button (the leftmost in the row of five, just to the left of the checkmark button). Select the words "Java Target" on the left hand side of the resulting window. The right hand side should now be telling you that you're working on a Java Application, and that its "main class" is "TrivialApplication". Change the main class to the name of the class you used in step 1, e.g. "FunWithStrings". Do not add the ".java" suffix, and be sure to spell it exactly the same way as you did in step 1.
If you run the program and get an error message saying "Could not find the specified file," it probably means you missed one or more of the above steps.

Yes, this is a royal pain. Believe it or not, all this stuff is actually useful to professional programmers using CodeWarrior; it's just unfortunate that you have to deal with it too.

Playing with Input and Output

Modify your String program, above, to send output to a disk file named "StringExamples" instead of (or in addition to) the screen.

Next, modify it to read a line from the keyboard and write several variants of the line (upper and lower case, concatenated with various other strings, the middle character, etc.) to a disk file.

Add a suitable prompt and flush() call to your program, so the keyboard input part is friendlier.

Modify your program so it reads the name of a file from the keyboard, then reads from that file and does various strange things to the contents, writing the results to another file and to the screen.

To be turned in:

GreetingMaker

Exercise 2 on page 77 of the Arnow & Weiss textbook.

WebHead

Exercise 1 on page 81 of the Arnow & Weiss textbook.

How to turn in your homework

You have been assigned to write two Java applications. The easiest way to give them to me is probably to send me an email, attaching the source code (e.g. GreetingMaker.java and WebHead.java). I don't need project files or any of that stuff unless you've chosen to write your program in more than one source file (which shouldn't be necessary at this point in the semester).
Last modified: Tue Sep 22 11:43:58 EDT 1998
Stephen Bloch / sbloch@boethius.adelphi.edu