## CS 1401, Exam #3

Date: Friday, November 3, 2006, 9:30 am
Name (please type legibly, ideally in block letters): ______________________________________________________________________

1a. Write a method named volume for computing the product of three given real numbers h, w, and l.

1b. Call (invoke) your method volume in the main method to compute the product of the three numbers h = 2.0, w = 2.0, and l = 2.0. (You do not need to write the entire main method, just the part that assigns values to h, w, and l, and calls your method.)

1c. Trace, step by step, how the computer will perform the needed computations, and check that the result is indeed correct.

```

```
2a. Define a class Box whose elements are box-shaped creatures; each creature is characterized by its name, its height, its width, and its length. Your class should contain a constructor method, accessor methods, mutator methods, and a method for computing the volume of the box-shaped creature.

2b. Use your class in the main method to define a new creature "Cuby" of type Box with height = width = length = 1.0. Compute and print Cuby's volume; then, simulate how Cuby grows: replace all the parameters with the larger value 2.0, and compute and print the new volume.

```

```
3a. Write a piece of code that, given an array h of integers, computes the average of all the elements in this array.

3b. To check the correctness of the code you wrote in Part 3a, write a piece of code that defines a new array h consisting of 3 elements of type integer and assigns, to elements of this array, values 1, 3, and 0. Trace step-by-step how the piece of code you wrote in Part 3a will compute the average value of this array. Hint: the desired average is equal to (1 + 3 + 0) / 3 = 1.333...

```

```
4a. Write a method that, given an array h of integers, computes the largest element of this array.

4b. To check the correctness of your method, write a piece of code that defines a new array z consisting of 3 elements of type integer and assigns, to elements of this array, values 1, 3, and 0. Trace step-by-step how the piece of code you wrote in Part 4a will compute the largest element of this array. Hint: the desired largest element is max(1, 3, 0) = 3.

```

```
5. Name main GUI components, and briefly explain their use.