CS100M Spring 2004 Lab 11 Note: It's likely that work will need to take place after lab. Follow these steps sequentially, starting from (1). But, the TAs will briefly explain the background of each of the steps before the lab finishes. 1) Discussion: + Review: What is a character? + Review: What is a string? + Java's representation of Strings as objects + The background for each of the following steps. 2) Explain how to find info on Strings (2 minutes): + Savitch (see Index) + API (see course website) + Everyone should access the API and find built-in class String 3) Discuss how to make Strings: + See constructors in String API - literals - using arrays of chars - supplying another String Task 1: Create a program Task1.java that creates the String "ABC" using the above 3 approaches. 4) String Methods: + see indexOf, toCharArray, toUpperCase, toLowerCase, charAt, length() + skim other methods Task 2: Create a program Task2.java that converts the array of characters {'h','e','l','l','o'} to to an uppercase String with two techniques: (a) using the String API (b) only using character arithmetic (review MATLAB notes...) Output your results for both approaches. Task 3: Create a program Task3.java that generates a random array of 10 keyboard characters (what is the range of ASCII values?). Convert the array to a String. Write a method that counts how many non-alphabetic characters are in the String. Write another method that extract the alphabetic characters and creates a new String out of them. Write a method that uses your data to test these other methods. 5) Command-line input: + what is args in main? - an input parameter to the main method - supplied at the command prompt - type is array of Strings + handy methods: wrapper classes! - see classes Integer, Double, Boolean, .... - look for methods called parseInt, parseDouble, ... - what do these methods do? Task 4: Create a program Task4.java such that you can call it with this command-line: > java Task3 3.0 2.0 1.0 -2.0 where the first two numbers represent the real and imaginary components of a Complex number, respectively. The same pattern is true for the second pair of numbers. Your program will convert the String inputs to numerical values, create Complex numbers (see Lab 9), multiply them, and then report the result. Your program must check for an illegal number of inputs! 6) Zip your files together in e11.zip and submit on CMS. Note the extended due date because of the extra work.