CS 1401, Exam #3

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

1a. Write a method named total for computing the sum of three given real numbers s, m, and f.

1b. Call (invoke) your method total in the main method to compute the sum of the three numbers s = 2.0, m = 2.0, and f = 2.0. (You do not need to write the entire main method, just the part that assigns values to s, m, and f, 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 Process whose elements are processes; each process is characterized by its name, the duration s of its starting part, the duration m of its main part, and the duration f of its finishing part. Your class should contain a constructor method, accessor methods, mutator methods, and a method for computing the overall time of a process.

2b. Use your class in the main method to define a new process "test" of type Process with s = 10, m = 30, and f = 10. Compute and print the overall time of the test (the result should be 10 + 30 + 10 = 50); then, replace s and f with 15 minutes, m with 50 minutes, and compute and print the new total process time.

2c. Trace your program step-by-step.















































3a. Write a piece of code that, given an array h of integers, computes the sum 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 10, 30, and 10. Trace step-by-step how the piece of code you wrote in Part 3a will compute the sum of all the elements of this array.



















































4a. Write a method that, given an array h of integers, computes the smallest 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 2, 4, and 0. Trace step-by-step how the piece of code you wrote in Part 4a will compute the smallest element of this array. Hint: the desired smallest element is min(2, 4, 0) = 0.





















































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