Chapter 1 Review Exercise Solutions
R1.1
Programs are sequences of instructions and decisions that a computer carries out to achieve a task. Programming means designing and implementing the instructions, as opposed to using their results. 
R1.2
A household appliance carries out one task (or perhaps several tasks) for which it was designed. A computer can be programmed to carry out arbitrary tasks that the designers of the computer never envisioned.
R1.3
There are several possible answers; here is a typical one. 
1.	Point my browser to http://briefcase.yahoo.com 
2.	Type in my username and password when prompted 
3.	Click on the Select file button 
4.	Select the file HelloPrinter.java in the directory c:\myfiles from the file dialog box
5.	Click Ok in the file dialog box
6.	Click on the Upload button 
7.	Wait for the file upload to complete 
R1.4
Answers may vary; the following are typical.
Sample file: c:\myprograms\HelloPrinter.java
Java interpreter: c:\Program Files\Java\jdk1.5.0\bin\java.exe
Run-time library: c:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar
R1.5
Syntax errors are discovered by compiling the program and noting any problems displayed by the compiler. The compiler will not translate the program into machine code until all the syntax errors have been corrected. The compiler will also attempt to report as many syntax errors as it can find. 
Logic errors are not readily obvious because the compiler will not detect them as it compiles the program. These types of errors are discovered by carefully examining the output and testing the program.
R1.6
Compile-time errors:
public class HelloPrinter
{  
   public static void main(String[] args)
   {  
      System.outprint("Hello, World");
/*             ^^ missing '.' */
   }
}       
public class HelloPrinter
{  
   public static void main(String[] args)
   {  
      System.out.print("Hello, World);
/*                                 ^^ missing '"'  */
   }
}       
public class HelloPrinter
{  
   public static void main(String[] args)
   {  
      System.out.print("Hello, World")
/*                                   ^^ missing ";"  */
   }
}       

Run-time error:
public class HelloPrinter
{  
   public static void main(String[] args)
   {  
      System.out.print("Hello, Wrold");   
   }
}       
R1.7
3 + 4
7
34
R1.8
	Start with a year of value 0, a month of value 0, and a balance of $10,000
	Repeat the following while the balance is greater than 0
		Multiply the balance by 1.005.
		Subtract 500 from the balance.
		Add one to month.
		If the month is 12
			Set month to 0.
			Add one to year.
	Year has the answer.
R1.9
If the starting balance is large enough and the interest rate large enough such that the first month’s calculation of interest exceeds the monthly expenses, then you will never deplete your account and the algorithm will never terminate.

Modified algorithm:
	Ask the user for balance, interest rate, and monthly expenses.
	If balance x interest is greater than monthly expenses
		Tell the user you’re in good financial shape and quit.
	Otherwise, start with a year of value 0, a month of value 0 and a balance of $10,000
	Repeat the following while the balance is greater than 0
		Multiply the balance by (1 + (interest rate times .01 divided by 12)).
		Subtract monthly expenses from the balance.
		Add one to month
		If the month is 12
			Set month to 0.
			Add one to year.
	Year has the answer.
R1.10
Calculate the overall surface area of the house without windows and doors.

surfaceArea = (2 x width x height) + (2 x length x height) 
		– (number of windows x windowWidth x windowHeight)
		- (number of doors x doorWidth x doorHeight)
R1.11
Calculate car cost = (one-way distance x miles per gallon x 4) + (one-way distance x 0.05)
If the car cost > train ticket price
	Ride the train.
Otherwise drive.
R1.12
work mileage = number of work days x one-way distance x 2
total miles = ending mileage – beginning mileage
fraction of commute = work mileage / total miles
R1.13
The computer cannot accurately predict what the price of gas will be on a daily basis (or know what day you will go to the gas station) and how many actual miles you will drive each year.