Learn To Program With
Java
McGraw Hill/Osborne
0072-131-896
Errata and
Source Code
(Last update: July
27, 2011)
Interested in Source Code? You can download a Zip
File (it's not large, about (95 Kb) of all the Examples and Exercises from the
book by clicking here.
Once downloaded, uncompress the file, and a folder called LTPJFILES will be
installed on your PC. There are subfolders called Examples, Grades and Practice,
with subfolders for each chapter in the book. In order to run the code, you'll
need to compile the source code into Java Bytecode classes.
Every author endeavors for perfection. My apologies for the typos that have slipped
through. We'll do our best to have these corrected for the next printing.
Chapter 1
- Page 35. Ward's description of how to calculate
an English grade says that the midterm and final exam grades should be
multiplied by 0.2--both should be 0.25.
Chapter 2
- Page 44. The Java Developer's Kit has been
updated to version 1.4. Here's the correct link.
http://java.sun.com/j2se/1.4/download.html
- Page 45 says "Java source file must end with a period, followed by the word 'Java'."
The extension should be in lower case.
- Page 46, third paragraph refers to 'Java
Developer's Kit'--this should be 'Java Development Kit". Also, same
correction applies to pages 58 and in Chapter 4.
- Page 47, paragraph after second screen shot.
"I also need to specify Text Document in the Save As Type drop-down
list box." should be "I also need to specify All Files in the Save
As Type drop-down list box."
- Pages 47 and 52. This is not an error, but the
main() method is shown differently in the diagrams on Pages 47 and the text
on Page 52. The diagrams show (String[] args) and the text (String args[]).
The fact that the code can be written either way is not discussed until
Chapter 10.
- Page 49, NOTE: "circled in red and it is
indeed..." should be "circled and it is indeed..."
- Page 58.
Diagram has numerous misspellings:
outpot rather than output
man rather that main
orgs rather than args
[] missing after "orgs"
Chapter 3
- Page 72, line 5. "to
local variable" should be "to a local
variable.
- Page 72, Example 3_2.
int number = 23;
should
be
int number2 = 23;
- Page 86, under the Byte topic. "The Byte
data type can hold only whole, positive numbers" should be "The
Byte data type can hold only whole numbers"
- Page 100, fifth line of code. The code variable
should be 'evennumber2' not 'evennumber1'.
- Page 100, first paragraph. "a
result of 1 from
the modulus operation indicates it mod’d an even number and a result of 0
from the modulus operation indicates it mod’d an odd number"
should
be
"a result of 0 from the modulus
operation indicates it mod’d an even number and a result of 1 from the
modulus operation indicates it mod’d an odd number."
- Page 112, Example 3_29. Bad layout for the
code. You can't break a quoted string in the middle. This
if (name == "Smith" & number == 22) System.out.println("both
sides
of the AND expression
are True"0;
should
be
if (name == "Smith" & number == 22) System.out.println
("both
sides of
the AND expression are True");
- Page 113, Example 3_30. Bad layout for the code. See Page 112,
Example 3_29 above.
- Page 115, Example 3_31. Bad layout for the code. See Page 112,
Example 3_29 above.
- Page 116, Example 3_32. Bad layout for the code. See Page 112,
Example 3_29 above.
- Page 117, Example 3_33. Bad layout for the code. See Page 112,
Example 3_29 above.
- Page 118, Example 3_34. Bad layout for the code. See Page 112,
Example 3_29 above.
- Page 119. This line of code
System.out.println number < 13 !! number > 13
should
be
System.out.println number < 13 | number > 13
Chapter 4
Chapter 5
-
Page 187, table. Step 6 reads '2True'--should
be 'True'
- Page 193, towards the bottom of the page.
"(int counter = 2;"
should be "(int counter = 3;"
- Page 200, second sentence. "The For loop
begins with the word..." should read "The While loop begins with
the word..."
- Page 207, about two thirds of the way down the
page. "Prior to moving on, I repeated that
my earlier assertion that one of the biggest mistakes" should be
"Prior to moving on, I repeated my earlier assertion that one of the
biggest mistakes"
- Page 208, Exercise 5-9. This line of code
System.out.println(response);
should not be there--please delete
it.
- Page 211, Exercise 5-10, Graes Program. A
reader has pointed out that if the user immediately clicks on the Cancel
button when asked if there are grades to calculate, the program bombs. You
can fix that behavior by adding a few lines of code.
String
moreGradesToCalculate;
moreGradesToCalculate = JOptionPane.showInputDialog(
"Do you want to calculate a grade?");
if(moreGradesToCalculate == null) {
JOptionPane.showMessageDialog
(null, "You clicked on the Cancel button");
System.exit(0);
}
moreGradesToCalculate = moreGradesToCalculate.toUpperCase() |
- Page 215, step 11. "Yyou should be
thanked.." should be "You should be thanked..."
- Page 216. On the sixth line of text, there is a
character after "moreGradesToCalculate".
Chapter 6
- Page 222, 2nd paragraph under
'What Is a Method'. I tell you that we'll be creating three methods called
calculateEnglishStudent(), calculateMathStudent, calculateScienceStudent.
Actually, the three methods we created are: calculateEnglishGrade(),
calculateMathGrade(), calculateScienceGrade().
- Page 222, second to last line of
text--"write" should be "right"
- Page 244, ninth line. "A
variable declared in a class, but are
not part of any method, are
either Instance or Class variables."
should be "Variables declared in a class, but not part of any method,
are either Instance or Class variables."
- Page 248, steps 15 and 16. "Clicking the
OK button. The program..." should be "Click the OK button. The
program..."
- Page 248, next to last paragraph. "... I
was a little confused about the two variables, oldBalance and balance."
should be "...I was a little confused about the two variables, balance
and newBalance."
- Page 253, third line. displayBalance()
should be getBalance().
- Page 255, third line. "it
illustrates the concept over
method overloading" should read "it
illustrates the concept of method
overloading"
- Page 256, line 27. "you’re
trying to define to identical
methods." should read "you’re trying to define two
identical methods."
- Page 260, Grades class. The
displayGrade() headers are passing finalexamGrade as an argument--this
should be finalExamGrade.
- Page 262, second paragraph. I
tell you that we created three methods called calculateEnglishStudent(),
calculateMathStudent, calculateScienceStudent. Actually, the three methods
we created were: calculateEnglishGrade(), calculateMathGrade(),
calculateScienceGrade().
Chapter 7
- Page 276. Blaine's question needs a
question mark.
- Page 278, line 26. "Return types
for methods are required except in the case of a constructor methods"
should read "Return types for methods are required except in the case
of a constructor method."
- Page 284. Screenshot doesn't match
code in Banner's constructor. The words 'Overloaded constructor' should be
'overloaded constructor'
- Page 289. Second mention of executing
the howMany() method shows the display() method on the following line of
code.
- Page 291. "Has the value of the
Class variable ... the howMany() method of the second Banner object..."
should read "Has the value of the Class variable ... the howMany()
method of the first Banner object..."
- Page 291. "By the way, notice how
we used the first object to update the Class variable and the second object
to display its value" should read "By the way, notice how we used
the second object to update the Class variable and the first object to
display its value"
- Page 294. Example7_7 should have been Example7_8. That's where
you'll find the code in the completed exercises.
- Page 296
//end of makeWithDrawal method
should
be
//end of makeWithdrawal method
... is not a valid student type");
should
be
... is not a valid banking function")'
- Page 299, Exercise 7-2, Step 2. Save your source file as
Practice7_1, not Practice7-2..
- Page 305, code. No need to declare the research
variable--it's not used in the MathStudent class.
- Page 307, step 4. Incorrectly indicates you
should test MathStudent class--it's the ScienceStudent class.
Chapter 8
- Page 324. Line of text just above the Note:
"begin able" should be "being able"
- Page 326, line 19. "specifiers
for Instance variable
created from other classes are not checked" should read "specifiers
for Instance variables created from
other classes are not checked"
- Page 329, Example8_6. This program will not
compile because the Instance variables in Student are private. I should have
pointed that out a little more forcefully than saying 'With a public
Instance variable..."
- Page 333, third line after setAge() code.
"SetAddress() contains validation code..." should be
"SetAge(0 contains validation code..."
- Page 334, third sentence. "So Mutator
methods cam return a value?" should be "So Mutator methods can
return a value?"
- Page 349, Exercise 8-4. I've already received a
number of emails from people wondering why I had you go through so much
trouble to create Mutator methods in the EnglishStudent, MathStudent and
ScienceStudent classes, only NOT to use them at all in the Grades class.
Temporary insanity perhaps. Fortunately, it's easy enough to utilize them.
In each one of the Student classes, modify the calculate() method to utilize
the various get... Methods to update the Private Attributes. For instance,
in the EnglishStudent class on Page 341, use this code in the calculate()
method...
-
public void calculate()
{
setMidterm(Integer.parseInt(JOptionPane.showInputDialog
("Enter the Midterm Grade" )));
setFinalExamGrade(Integer.parseInt(JOptionPane.showInputDialog
("Enter the Final Examination Grade" )));
setResearch(Integer.parseInt(JOptionPane.showInputDialog
("Enter the Research Grade" )));
setPresentation(Integer.parseInt(JOptionPane.showInputDialog
("Enter the Presentation Grade" )));
finalNumericGrade =
(midterm * ENGLISH_MIDTERM_PERCENTAGE) +
(finalExamGrade * ENGLISH_FINALEXAM_PERCENTAGE) +
(research * ENGLISH_RESEARCH_PERCENTAGE) +
(presentation * ENGLISH_PRESENTATION_PERCENTAGE);
if (finalNumericGrade >= 93)
finalLetterGrade = "A";
else
if ((finalNumericGrade >= 85) & (finalNumericGrade < 93))
finalLetterGrade = "B";
else
if ((finalNumericGrade >= 78) & (finalNumericGrade < 85))
finalLetterGrade = "C";
else
if ((finalNumericGrade >= 70) & (finalNumericGrade < 78))
finalLetterGrade = "D";
else
if (finalNumericGrade < 70)
finalLetterGrade = "F";
}
} |
This will trigger the Mutator methods for
the midterm. finalExamGrade, research and
Presentation Attributes.
- Page 351, Exercise 8-4. Step 3 says to save
your source file as ScienceStudent.java. We're working on the Grades class
here--save your file as Grades.java instead.
Chapter 9
- Page 361. In the first line of text,
"calculate() method" should read "display() method"
- Page 362, above the screen shot. "I then
compiled both the Student class and Example9_1 class" should be "I
then compiled both the Employee class and Example9_1 class"
- Page 362, last sentence. "It was in the
getGrossPay() Access method" should be "It was in the getGrossPay()
Accessor method"
- Page 362, line 19. "to the
string "Gross Pay:":"
should read "to the string "Gross
Pay:"""
- Page 377, line 36. "One
consequence of the class begin
designated" should read "One consequence of the class being
designated"
- Page 381. "For instance, this code would
prevent the Mutator method called getName()..." should be "For
instance, this code would prevent the Accessor method called getName()..."
- Page 386, third sentence indicates that we are
modifying the EmployeeBase class. Actually, we're modifying the
HourlyEmployee class.
- Page 387, Blaine's question should read
"...more than ONE interface..."
- Page 400, last sentence indicates that next
week we'll examine handling errors. The next week's topic is actually
arrays.
Chapter 10
- Page 413, under 'Adding Data to the Elements of
an Array. Code reads
grades[2] = 82;
It
should read
grades[2] = 64;
int rhonda[] = new int{10];
The
number 10 is enclosed by a left curly brace and a right bracket--it should read
int rhonda[] = new int[10];
grades[counter] = 80
is
missing a semicolon. It should read
grades[counter] = 80;
- Page 416, discussion. "Once again, we
initialize the value of our accumulator variable to 6..." should be
"Once again, we initialize the value of our counter variable to
6..."
- Page 421, line 14. "accumulator
= 0 + 90" should
read "accumulator = 0 + 82"
- Page 421, line 20. "accumulator =
90 +
91" should read "accumulator = 82 +
91"
- Page 429, 3rd row in the diagram: 64.56 should
read 64,56
- Page 430, line 9. "...each field made up of one
hundred rows and columns" has a comma after it that shouldn't be there
- Page 435, line 10. "the
outer loop is intended to process the columns"
should read "the outer loop is intended to
process the rows"
- Page 435, line 11. "and the
inner loop is intended to process the rows."
should read "and the inner loop is intended to
process the columns."
Chapter 11
- Page 450, 5th line from bottom. "opening a valve or an
engine" should be "opening a valve on an engine"
- Page 478, line 11. "which
is what we want
our Java program will
do." should read "which is what we
want our Java program to do."
- Page 484, line 18. "I remember
seeing that it in Exercise 11-1."
should read "I remember seeing that in Exercise 11-1."
Chapter 12
- Page 502, 2nd paragraph. "Again, there's
more control over the placement of these objects than there is with
FormLayout..." should be "Again, there's more control over the
placement of these objects than there is with FlowLayout..."
- Page 509, second to last line of text
"high degree or probability" should be "high degree of
portability"
- Page 510, fourth paragraph. setRisizable() method in bold should
be setResizable()
- Page 522. c.add(lblStudentType);
occurs twice in the code.
- Page 524. Notice the word "LEFT"---we
actually coded "CENTER" on Page 521
- Page 525. c.add(lblStudentType);
occurs twice in the code.
- Page 526, line 15. "coordinates, x
and, and height and width" should be "coordinates, x
and y, and height and width"
- Page 527. Exercise 12-2. Save file as 'GradesGUI"
NOT DrawGUI
Chapter 13
- Page 538, line 19. "which
of the three
RadioButton objects" should be "which of the two
RadioButton objects"
- Page 545. Dave's question "Is there
anyway..." should be "Is there any way.."
- Page 547. "We'll need to create a
Constructor method in the Listener class that accepts an object or our GUI
class..." should be "of our GUI class"
- Page 550, line 24. passed a
reference to the Frame"); should be passed a reference to the Frame");
- Page 558 onward. Starting on page 558
(and continuing through the example on the following pages), what is
mentioned as "override" should actually be
"overload". The text is referring to two methods with the same
name but with different signatures, as opposed to a method in a subclass
overriding a method in a superclass.
- Page 573, last line. "need to
create three more Listener
classes" should be "need to create two
more Listener classes"
- Page 576, line 25. "when the use
closes the frame." should be "when the user
closes the frame."
- Page 580. First line of code is repeated from
the previous page.
The Number of visitors to this page since
December 3, 2001
© 1998-2002, Smiley and Associates, Inc.
Revised - May 23, 2003
webmaster@johnsmiley.com
[ Home
| Books
| Links
| My book!
|