Errata for Computing with Java(TM): Programs, Object, Graphics, Alternate Second Edition Corrections to the Second Printing (See Below for Corrections to the first Printing) p. 1 Line 8 Change "Object-oriented" To "Object-Oriented" p. 2 Line 8 Omit "Introduce basic computing concepts." p. 15 Line 6 Change "wait" To "waits" p. 15 Line 19 Change "program continues executing" To "system continues executing" p. 21 Line 3 from the bottom Change "Object-oriented" To "Object-Oriented" p. 43 Figure 2.6 Change "selectMoney" To "selectCandy" p. 64 Line 7 from the bottom Change "2.11" To "2.10" p. 164 Example 4.6 before "public" Add "import javax.swing.*; import java.text.*" p. 208 Line 11 of Figure 5.3 Change "ch" To "str" p. 234 line 26 Change ";;" To ";" p. 237 Figure 5.20 Address should be: street : String city : String state : String zip : String p. 240 Lines 11, 12, and 13 from the bottom Change "l" To "len" p. 241 Note 2 Change "name and address" To "first name and last name" p. 244 Exercise 1 Move "i. stores a value wihtin a method" to the right p. 259 Line 9 from the bottom Change "HelloApplet.class" To "HelloCount.class" p. 263 Line 24 Change "Lucinda" To "Lucida" p. 267 Note 2 Change "return" To "returns" p. 271 Line 4 Change "variable" To "variables" p. 276 Line 13 Change "send" To "sends" p. 277 Exercise 22 Omit "in the concertComing method" p. 288 Line 8 Change "illustrate to" To "illustrate" p. 293 Question 2 Change "and are" To "and which are" p. 294 Line 14 Change "interest rate" To "concert schedule" p. 310 Line 7 from the bottom Omit "as in Example 7.7" p. 348 Line 9 from the bottom Change "8.11b show" To "8.11b shows" p. 395 Line 2 from the bottom Change "Io.readInt("How many characters?");" To "Integer.parseInt(JOptionPane.showInputDialog ("How many characters?"));" p. 396 Line 2 Change "Io.readChar("Enter next character");" To "JOptionPane.showInputDialog("Enter next character") .charAt(0);" p. 396 Problem 13b Change "of to" To "of part a to" p. 410 Lines 10 and 12 Change "5.8" To "5.7" p. 427 Change Note 7 To "s[0] = new Line(20,50,60,70); The line has coordinates (20,50) and (60,70)." p. 430 Line 24 Change "contain" To "contains" p. 441 Remove the extra "Figure 9.21" label p. 445 Line 23 Change "intacctType" To "int acctType" p. 509 Line 3 Change "tempertartures" To "temperatures" p. 509 Line 24 Change "temerature" To "temperature" p. 532 Before line 12 from the bottom Add "import java.io.*;" p. 533 Line 24 Change "file" To "array" p. 594 Line 14 Change "8.7" To "13.2" p. 598 Top line Change "10.8" To "13.3" p. 602 Line 4 Change "allow" To "allows" p. 608 Bottom line Change "five" To "six" p. 623 Line 5 Change "as a" To "as" p. 634 Line 5 Change "return" To "returns" p. 649 Line 16 Change "search" To "searched" p. 656 Line 11 Change "different" To "difference" p. 656 Line 17 Change "method" To "methods" p. 661 Line 2 Change "to moved" To "to be moved" p. 666 Bottom line Change "To make thread" To "To make a thread run" p. 672 Top line Remove the extra "Figure 15.3" label p. 694 Line 13 from the bottom Change "the last section" To "Section 15.1" p. 697 Line 15 from the bottom. Change "1.18" To "15.12" p. 698 Change "Example 1.19" To "Example 15.13" p. 704 Exercises 15 and 16 Change "1.20" To "15.14" p. 706 Change 2.c to "new FileReader("x")" Change 3.c to "wait" Change 3.i to "Object" p. 707 Exercises 6 an 7 belong at the end of Chapter 16. p. 708 Omit Exercises 17, 18, and 19. They are in Chapter 16. p. 709 Omit Exercises 24, 25, and 26. They are in Chapter 16. p. 715 Lines 3, 8, 12, and bottom line p. 716 Line 10 Change ".java/" To ".java" p. 735 Note 2 Change "2.9" To "16.9" p. 768 Figure 17.15 "Name" should be "CustomerName" p. 768 Line 2 from the bottom Change "VARCHAR(4)" To "CHAR(4)" p. 769 Line 10 Change "VARCHAR(2)" To "CHAR(2)" Line 16 Change "VARCHAR(6)" To "CHAR(6)" Line 22 Change "VARCHAR(4)" To "CHAR(4)" Line 22 Change "VARCHAR(2)" To "CHAR(2)" Line 14 from the bottom Change "CHAR(4)" To "VARCHAR(4)" p. 770 Line 7 Add the line "con.close();" after "stmt.close();" p. 787 Line 20 Change "getInt" To "getString" p. 791 Line 3 from the botom p. 792 Line below Figure 3.18 p. 794 Line 2 Change "Order" To "Orders" p. 794 Line 6 Change "'1999-03-22" To "'1999-03-22'" p. 804 Line 14 from the bottom Change "in" To "it" p. 812 Line 5 Change "need" To "needed" p. 842 Line 11 from the bottom Change "request" To "requests" p. 876 Example 19.7 Change "smile=(Smiley)Beans.instantiate(null,"smiley.Smiley");" To "ClassLoader cl = this.getClass().getClassLoader(); smile=(Smiley)Beans.instantiate(cl,"smiley.Smiley");" p. 882 Line 6 from the bottom Change "name" To "named" p. 883 Line 8 from the bottom Change "Figure 13" To "Figure 20.3" p. 884 Line 6 Change "use" To "used" p. 886 Bottom Line Change "is" To "if" p. 889 When using J2SE version 1.4 or higher no additional download is needed to run Examples 20.1 through 20.6. p. 889 Line 7 Change "classpath." To "classpath, except when using the J2SE version 1.4 or higher which includes the required packages." p. 889 For J2SE v. 1.3, when using the jax_xml_pack-summer-02 or later Change the command to compile Sax.java to "javac -classpath %jaxp_home%\sax.jar Sax.java" Change the command to run Sax to "java -classpath .;%jaxp_home%\sax.jar Sax authorSimple.xml false" p. 890 Line 21 from the bottom Change "import org.xml.sax.XMLReader" To "import org.xml.sax.helpers.ParserAdapter;" p. 890 Omit Lines 17 and 18 from the bottom. "import org.xml.sax.InputSource; import java.io.FileReader;" p. 891 Line 4 from the bottom Change "in" To "it" p. 891 Line 27 Change "XMLReader reader = parser.getXMLReader();" To "ParserAdapter reader = new ParserAdapter(parser.getParser());" p. 891 Line 30 Change "(new InputSource(new FileReader (args[0])));" To "("file:" + args[0]);" p. 892 Change Note 14 to " ParserAdapter reader = new ParserAdapter(parser.getParser()); A ParserAdapter wraps a SAX1 Parser and makes it act as a Sax2 XMLReader." p. 893 Change Note 16 to "reader.parse("file:" + args[0]); The parse method will parse an XML document where the argument is the URL of the document." p. 894 Line 3 Change "Example 1" To "Example 20.1" p. 895 Line 8 from the bottom p. 896 Top line Change "org.w3c.com" To "org.w3c.dom" p .896 For J2SE v. 1.3, when using the jax_xml_pack-summer-02 or later Change the command to compile Dom.java to "javac -classpath %jaxp_home%\dom.jar Dom.java" Change the command to run Dom to "java -classpath .;%jaxp_home%\dom.jar Dom author.xml false" p. 900 Add after line 2 import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; p. 900 Replace "System.out.println(customer);" with TransformerFactory f = TransformerFactory.newInstance(); Transformer transformer =f.newTransformer(); DOMSource = new DOMSource(document); StreamResult result = new StreamResult(System.out); transformer.transform(source, result); System.out.println(); p. 902 Below Figure 20.14 Change "produces" To "produced" p. 903 Line 6 Change "stlyesheet" To "stylesheet" p. 904 For J2se v. 1.3, when using the jax_xml_pack-summer-02 or later Change the command to compile XmlToHtml to "javac -classpath .;%jaxp_home%\jaxp-api.jar XmlToHtml.java" Change the command to run XmlToHtml to "java -classpath .;%jaxp_home%\jaxp-api.jar XmlToHtml authorSimple.xml authorSimple.xsl authorSimple.html" p. 904 Line 17 Change "d:\jaxp-1.1ea" To "%JAXP_HOME%" pp. 915-918 The Barnes and Noble Price Quote service is not available from this site. Here is a replacement using a currency converter service. /* java TrySoapCur services.xmethods.net 80 /soap England Japan */ import java.net.*; import java.io.*; public class TrySoapCur { public static void main(String [] args) { String s; if (args.length != 5){ System.out.println ("Usage: java TrySoapCur host port file country1 country2"); System.exit(1); } try { int port = Integer.parseInt(args[1]); Socket server = new Socket(args[0],port); System.out.println("Connected to host " + server.getInetAddress()); BufferedReader fromServer = new BufferedReader (new InputStreamReader(server.getInputStream())); PrintWriter toServer = new PrintWriter (server.getOutputStream(),true); toServer.println("POST " + args[2] + " HTTP/1.0"); toServer.println("Host: " + args[0]+ ':' + args[1]); toServer.println("Content-Type: text/xml"); toServer.println("SOAPAction: \"\""); String request = "" +"" +" " +" " +args[3]+ "" +" " +args[4]+ "" +" "; toServer.println("Content-Length: " + request.length()); toServer.println(); toServer.println(request); while (!(s=fromServer.readLine()).equals("")) System.out.println(s); while ((s=fromServer.readLine()) != null) System.out.println(s); fromServer.close(); toServer.close(); server.close(); }catch(Exception e) { e.printStackTrace(); } } } p. 917 Line 10 Change "%SOAP_HOME%\lib\xerces.jar;%SOAP_HOME%\lib\mail.jar;" To "%JAXP_HOME%\jaxp-api.jar;%JRUN_HOME%\lib\ext\mail.jar;" p. 917 Line 11 Change "%SOAP_HOME%\lib\activation.jar" To "%JRUN_HOME%\lib\ext\activation.jar" p. 914 Bottom line p. 917 Line 11 Change "1576760235" To "0672319225" p. 918 Line 2 from the bottom Change "attributes" To "attribute values" p. 997 Add the answer for 35g "Math.ceil(-3.01)" p. 997 Answer to 27 Change "0" To "35" p. 997 Answer 41 Change "int choice = Io.readInt("Enter your choice, 1, 2 or 3");" To "String input = JOptionPane.showInputDialog("Enter your choice, 1, 2 or 3"); int choice = Integer.parseInt(input);" p. 998 Answer 43 Change "choice = Io.readInt("Enter your choice, 1, 2 or 3");" To "String input = JOptionPane.showInputDialog("Enter your choice, 1, 2 or 3"); choice = Integer.parseInt(input);" p. 998 Answer 5 Change "2.9" To "5.2" p. 1011 ch3 Answer to 3.a Add ; to the end of first line code p. 1011 ch3 Answer to 7 Change "e" To "c" Corrections to the First Printing p. viii Change the Chapter 15 title to "Multimedia" p. 11 Line 3 from the bottom Change "and 300" To "as 300" p. 20 Line 15 from the bottom Change "needed needed" To "needed" p. 26 Figure 1.16 Change "place an order pay" To "place an order pay" p. 36 Figure 2.3 Change "Abstract Boolean Break" To "abstract boolean break" p. 43 Bottom line Change "Vending" To "Vending1" p. 44 Line 10 Change "Vending(10, 15)" To "Vending1(10, 15)" p. 45 Line 14 Change "It used" To "It uses" p. 50 Line 1 Change "to identity" To "to identify" p. 61 Line 13 Change "be used" To "used" p. 63 Note 4 Change "Out test" To "Our test" p. 64 Figure 2.20 Change "Vending1" To "Vending2" p. 64 Bottom line Change "C and C++" To "C" p. 66 Line 2 from the bottom Change "of method" To "of the method" p. 71 Line 7 from the bottom Change "left" To "right" p. 72 Line 6 Change "is Java" To "is a Java" p. 76 Line 7 Change "operators," To "operators +=," p. 95 Example 3.3 Change the comment to "/* Uses if and if-else statements to determine * the coins needed to make change. */" p. 104 Line 14 Change "Pay2p = new Pay2Double.parseDouble(s));" To "Pay2 p = new Pay2(Double.parseDouble(s));" p. 105 Figure 3.9 lower-right rectangle Change "361" To "361.0" p. 124 Bottom Line Change "draw" To "g.draw" p. 128 Exercise 37 Change "16" To "36" p. 131 Line 20 Change "total")" To "total)" p. 133 Line 7 Change "bread" To "cereal" p. 133 Line 8 Change "Bread" To "Cereal" p. 133 Line 17 Change "45359237" To ".45359237" p. 133 Exercise 17 Change "7.4957181" To "7.4957" Change "14.109587" To "14.1096" p. 138 Line 8 Change "character" To "char" p. 153 The line below Figure 4.16 Change "4.13" To "4.16" p. 157 Exercise 11 Align "else" under "if" p. 167 Line 22 Change "or" To "for" p. 181 Line 7 p. 182 Line 13 Change "while" To "} while" p. 194 Line 7 Change "once" To "one" p. 202 Problem 27 Change "< 1" To "< .25" p. 212 Figure 5.5 Change "my String" To "myString" p. 215 Exercise 2 Change "Strings" To "String s" p. 224 Add as the first line in the main method "NumberFormat nf = NumberFormat.getCurrencyInstance();" p. 232 Figure 5.17 Change the last "serve burger" To "serve fries" p. 235 Note 7 Change "Cook cook" To "Cook joe" p. 242 Omit Note 8 p. 250 Line 2 Change "are" To "our" p. 254 Line 5 from the botton Change "//.java" To "//java" p. 257 Line 6 Omit " "HelloWorld!" " p. 263 Line 2 Change "differ ent" To "different" p. 264 Note 6 Change "Serif" To "Arial" p. 266 Line 15 Change the last "255" To "255)" p. 272 Add a blank line after the first three lines of the Output section. p. 274 Line 7 Change "county" To "country" p. 275 Line 3 from the bottom Change "respons" To "responds" p. 277 Exercise 22 Change "customer.study" To "customer1.study" p. 308 Lines 6, 8, 10, and 12 p. 311 Lines 10, 12, and 14 from the bottom Change "color" To "Color" p. 308 Lines 7 and 9 Change "color.getSelectedItem1)" To "color.getSelectedItem()" p. 311 Omit "private Color [] theColor = {Color.red,Color.green,Clolor.blue}; private String [] colorName = {"Red","Green","Blue"};" p. 311 Add Color c; as the first line of the paint method. p. 322 Note 6 Change "salects" To "selects" p. 350 Line 11 Change "Io.readInt("Enter an integer");" To "Integer.parseInt (JOptionPane.showInputDialog("Enter an integer"));" p. 358 Figure 8.20 Change "JoptionPane" To "JOptionPane" p. 366 Line 18 Change "dice.tossResults" To "tossResults" p. 375 Line 19 from the bottom Change "Sors" To "Sorts" p. 377 Line 11 from the bottom Change "Chapter 6" To "Chapter 8" p. 378 Line 4 from the bottom Change "runtimne" To "runtime" p. 402 Top line Change "form" To "from" p. 402 Lines 5 and 8 Change "SimpleSaving1" To "SimpleSavings1" p. 403 Line 5 from the bottom Change "SimpleSaving2" To "SimpleSavings2" p. 416 Line 6 Change "UseNewAnimals.java" To "UseNewAnimal.java" p. 423 Example 9.12 Add a right brace, }, at the end of the code. p. 424 Figure 9.11 Change "move(x,y)" To "move(xAmount,yAmount)" p. 427 Note 7 Change "s0 =new Line(2,5,6,7);" To "s[0] = new Line(20,50,60,70);" p. 429 Line 10 Change "5.8" To "5.7" p. 432 Line 11 Change "dradius" To "radius" p. 433 Line 11 Change "3.3" To "9.12" p. 433 Line 2 Change "object;s" To "objects" p. 440 Line 5 Change "accoutn" To "account" p. 450 Line 8 from the bottom Change "21-24" To "19-22" p. 462 Lines 15, 16, 17, and 27 Omit the semicolon at the end of the line. p. 491 Line 15 Change "f " To "if " p. 499 Line 2 from the bottom Change "keyPressed" To "keyTyped" p. 519 Line 17 from the bottom Omit "Enter an index from 0 to 2: 98" p. 527 Line 15 from the bottom Change ".10" To "2.10" p. 529 Line 22 Change "TotalCost.data" To "totalCost.data" p. 529 Line 6 from the bottom Change "form" To "from" p. 561 Line 3 from the bottom Change "use" To "used" p. 579 Line 9 Change "JPanel" To "JFrame" p. 638 Add a new line 8 from the bottom "time1 = System.currentTimeMillis();" p. 639 Line 4 Change "4747" To "2447" p. 665 Change the Chapter title to "Multimedia" and change page heading on the even-numbered pages in this chapter. p. 772 Add after Line 19 "import java.text.*;" p. 772 Add before the bottom line "NumberFormat cf = NumberFormat.getCurrencyInstance():" p. 810 Line 13 Change "use" To "uses" p. 885 Before Figure 20.5 Change " Figub re" To "Figure" p. 915 Line 7 from the bottom Change ">args[3]<" To ">"+args[3]+"<" p. 939 Line 2 Change "We include the documentation for the Java 2 Platform Standard Edition on the CD bundled with this text. It may be downloaded form" To "The documentation for the Java 2 Platform Standard Edition may be viewed or downloaded from" p. 995 Add 19 c. double d = (double)874; Add 20 c. 4 p. 997 Answer to 27 Change "35" To "0" p. 997 Omit the answer to 35g. p. 1002 Chapter 9, Answer 3 Change "50.00,3.5" To "1500.0, 0.35" p. 1011 Chapter 4, Answer 3 Change "i = Io.readInt("Enter an integer");" To "String input = JOptionPane.showInputDialog("Enter an integer"); i = Integer.parseInt(input);" p. 1012 Answer to 7.1 Change "Action, Item, Item" To "Action, Item, Item, Action"