Homework 4
CS201, Spring 2004


Due: 10AM, Friday, April 30

Please email your solutions to csun@calstatela.edu, and make sure to use CS201 Spring 04 HW4 as the subject of the email. The email should include your name, answers to Ex. 1 and 2, and the .java files for Ex. 3, 4 and 5 as attachments. I will check email timestamps, and late homework will not be accepted.


1. (12pt) Exercise 5.4 [D&D]. You do not have to explain where the errors are. Just show the corrected code.

2. (15pt) Exercise 5.14 (a),(b),(c),(e),(g) [D&D]

3. (15pt) Exercise 5.6 [D&D]

4. (20pt) Exercise 5.12 [D&D]. A "sentinel-controlled loop" basically means the program will keep asking for user input, until the user types in some  special value ("sentinel"), at which point the program stops looping and displays the result. We have seen an example of a "sentinel-controlled loop" in the Temperature lab exercise, where the "sentinel" value is 3. For this problem, any product number other than 1, 2, 3, 4, and 5 should be considered as the end of data entry.

5. (20pt) Excercise 5.16 [D&D]. To receive full credit for this problem, you must use for loop statement.