Learn To Program With
JavaSmiley 
Publishing
Errata and
Source Code
 
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.
Chapter 9
My thanks to 
Gary Mielak and Keith Monk for pointing out an issue with the 
Grades Project beginning with Chapter 9.
Specifically..
The set function does not prevent negative numbers or positive 
grade numbers, over a 100 from entering the calculation procedure.  It is the 
same for all 3 student types. 
In fact, the mutator() methods written in Chapter 8 are never 
used!
Resolution:
	I'm embarrassed to say this but...
	
	I wrote the first version of the book in 2002, and it's hard to believe that 
	an error of this kind has remained in it for over 20 years, but several 
	readers have recently found it.
 
	I started my detective work in the 
	chapter where I first use the mutator methods---chapter 8.
 
	This is a perfect illustration of how 
	being so close to a project that it hampers your ability to see the forest 
	for the trees---I must have tested this code only with the correct grades, 
	not the invalid grades. 
 
	It seems that neither I (nor my fictional 
	students) executed the code with negative numbers or numbers out of bound. 
 
	Let's use the midterm grade calculation 
	in the English class as an illustration.
 
	Although I wrote the
	setMidterm() mutator method, I never execute it 
	within the class! 
	Specifically within the
	calculate() method where the prompts for the 
	various grade components occur.
 
 
	The results of the input dialog are set 
	directly to the private variables, whereas they should be sent to the 
	various mutator() methods. 
	
	I've corrected the code for the midterm prompt within the
	calculate() method below---there are 2 ways to 
	achieve this. 
	
	The first executes the code as written now, then passes the midterm grade to 
	the setMidterm() method as an argument...
	
	  public void calculate()
	      {
	         midterm = Integer.parseInt(JOptionPane.showInputDialog
	          ( "Enter the Midterm Grade" ));
	         setMidterm(midterm);
	
	The second method is what most Java experienced programmers would 
	use---passing the result as an argument to the 
	setMidterm() method.
	
 
	  public void calculate()
	      {
	         setMidterm(Integer.parseInt(JOptionPane.showInputDialog
	          ( "Enter the Midterm Grade" )));
 
	Does that make sense?
 
	Of course, all 3 student classes need to 
	be modified to use the set mutator() methods.