Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 14 March 23, 2000. Exam Results Class Average was 69.4 –Median was 72.5 (which means there were some very low grades) Questions 31, 32, and 33.

Similar presentations


Presentation on theme: "Lecture 14 March 23, 2000. Exam Results Class Average was 69.4 –Median was 72.5 (which means there were some very low grades) Questions 31, 32, and 33."— Presentation transcript:

1 Lecture 14 March 23, 2000

2 Exam Results Class Average was 69.4 –Median was 72.5 (which means there were some very low grades) Questions 31, 32, and 33 counted 5, 15, and 20 points respectively. Short answers 2 each. Question 31 result = theString.compareTo( “hello” );

3 Question 32 public void printAllCards() { for ( int v = 0; v < value.length; v++ ) { for ( int s = 0; s < suit.length; s++) { System.out.println( value[v] + “ of “ + suit[s] ); }

4 // Question_33.java import java.io.*; import java.util.*; public class Question_33 { public static void main( String[] argv ) { if ( argv.length != 1 ) { System.err.println( "You must give exactly one file name." ); System.exit( 1 ); } int count = 0; try { BufferedReader br = new BufferedReader( new FileReader(argv[0]) ); String inBuf; StringTokenizer st; while( null != (inBuf = br.readLine()) ) { st = new StringTokenizer( inBuf, ".,;:\"'?[]{}+_-=!@#$%^&*()<>" ); while ( st.hasMoreTokens() ) { System.out.println( st.nextToken() ); count++; } catch ( IOException ioe ) { System.err.println( argv[0] + ": " + ioe.getMessage() ); System.exit( 1 ); } System.out.println( "There were " + count + " words." ); System.exit( 0 ); }

5 Class java.lang.String (Chapter 10) Nine Constructors (see textbook) Comparisons –compareTo(), compareToIgnoreCase(), equals(), equalsIgnoreCase(), endsWith(), startsWith(), regionMatches() –equal() vs. = = [ StringCompare.java ]StringCompare.java Generators –substring(), toLowerCase(), toUpperCase(), trim(), replace(), concat(), toString() Converters: valueOf() [9 of them; see page 475] Utilities –charAt(), getBytes(), getChars(), indexOf(), hashCode(), lastIndexOf(), length()

6 Class StringBuffer Big speed advantage compared to class String Three Constructors Utilities –Length(), capacity(), setLength(), ensureCapacity() Getters –charAt(), getChars(), substring() Manipulators –reverse(), setCharAt(), insert() (10 of them), append() (10 of them), replace()

7 Class StringTokenizer Already covered in Exercises. See textbook for details.

8 Exercise 6 Write a Java application named Grep that takes any number of command line arguments. –If the first argument is “-i” do case insensitive comparisons. – The next argument is a “search string” –The next argument(s) are file names. Print each line in each file that contains the search string. –If there are multiple files, print the filename before each line. Will be done in two stages, 6a and 6b.


Download ppt "Lecture 14 March 23, 2000. Exam Results Class Average was 69.4 –Median was 72.5 (which means there were some very low grades) Questions 31, 32, and 33."

Similar presentations


Ads by Google