CS201, Spring 2004

Due: Wednesday, April 7

Please turn in a hard copy at the class, and send the java files (not the project or class files) of Excercise 3, 4, and 5 to cysun@cs.ucsb.edu by email attachment. Make sure to use CS201 Spring 04 HW1 as the subject of the email, and include in the email your name and student ID number, so I don't have to guess names from email addresses.

1. Read Chapter 1.1 - 1.14 and Chapter 2.1 - 2.7 of the textbook. Pay close attention to the tips about Good Programming Practice and Common Programming Error.

2. (5pt) Exercise 1.6 [D&D].

3. (10pt) Exercise 2.20 [D&D]

4. (10pt) Exercise 2.33 [D&D]. Only do it for the numbers from 5 to 8. Note that your program has to perform the calculation of the squares and cubes, not just simply printing the results.

5. (15pt) Given the lengths of the three sides a, b, and c, the area of a triangle can be calculated as

area
= sqrt(s(s-a)(s-b)(s-c)) where s
= (a+b+c)/2

Write a Java application to obtain the values of a, b, and c from input, and output the area
of the triangle. [McGuire]- Use JOptionPane for input
- Use either JOptionPane or System.out.println for output. Either way, the output should be "The area of the triangle is xxxx", where "xxxx" is the calculated area.