Computer Science 212
Project 1 hintsCopyright © 2005 by Dorothy L. Nixon. All rights reserved.
Table of contents
- The compareTo method of class String
- Using a StringTokenizer
- Displaying a large amount of text to a JOptionPane dialog box
Example files (download as ZIP file here)The example files may be downloaded in a ZIP file here.
Project 1 hints
- The compareTo method of class String
If you have not done so already, read the section of Tutorial 2 on how to use the Sun Java documentation.
In the Sun Java documentation for the java.lang package, look up the String class and read the description of the compareTo and compareToIgnoreCase methods. Below is a simple example program using the compareTo method:
The compareTo method can be used when sorting strings.
- Using a StringTokenizer
In the Sun Java documentation for the java.util package, look up the StringTokenizer class. Below are some simple example programs using StringTokenizer objects:
- StringTokenizerDemo.java (with data file demoInput.txt)
- StringTokenizerDemo2.java (with data file Names.txt)
- StringTokenizerDemo3.java (with data file Dates.txt)
- StudentFormat.java (with data file Students.txt)
The above programs use objects of the following classes for text file I/O:
The example program StringTokenizerDemo3.java uses a StringTokenizer in a manner somewhat similar to the way you'll be using it in the project. Note the use of the two-parameter constructor to create the StringTokenizer object.
- Displaying a large amount of text to a JOptionPane dialog box
The example programs below are variants of example programs for Tutorial 2 and Tutorial 3. The following programs display text to a text area (class JTextArea) on a JOptionPane message dialog box.
- ExamScores3.java (uses data file ExamScores.txt)
- SortingDemoAssertions3.java (uses data files numbers.txt, numbers2.txt, numbers3.txt, and numbers4.txt
- SortingDemoExceptionsTest3.java (uses class SortingDemoExceptions in SortingDemoExceptions.java, and uses data files numbers.txt, numbers2.txt, numbers3.txt, and numbers4.txt