CS 1401, Exam #4, MW 9-10:20 version

Date: Wednesday, November 27, 2013
Name (please type legibly, ideally in block letters): ______________________________________________________________________

On November 27, 1852, Ada Lovelace, the daughter of Lord Byron, died.

1. Describe, in detail, how Ada Lovelace contributed to computing.

2a. The programmer's productivity can be measured by the average number of lines of code that the programmer produces per day. Write a method named productivity that, given the number of lines of code produced by the programmer during a certain period of time and the duration d of this period, returns the programmer's productivity. In your method, throw an exception to take into account situations when the duration is zero.

2b. Throw an additional exception when the number of lines is negative.

2c. Call (invoke) your method productivity in the main method to compute the productivity of a programmer. Use try-catch in your main method to catch the two exceptions and print the corresponding error messages. On the example when a programmer coded 100 lines in 2 days, trace, step by step, how the computer will perform the needed computations, and check that the result is indeed correct.

3a. Define a class Programmer whose objects are different programmers. The description of each programmer should contain his/her name, the number of lines of code this programmer wrote, and the amount of time (in days) that the programmer works for the company. Your class should contain a constructor method, get- and set-methods, and a method for computing the programmer's productivity.

3b. Use your class in the main method to define a new object mario of type Programmer; assume that Mario programmed 1,000 lines of code in 20 days. Compute and print Mario's productivity. While you were computing, he has programmed 1,200 more lines of code in another 20 days. Use the set-methods to update the values in the corresponding object, and compute and print his updated productivity.

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

4a. Write a method that, given an array of programmers, returns the name of the most productive programmer.

4b. Test your method in the main program, by applying it to two programmers: Mario and Lauren; assume that Lauren programmed 3,000 lines of code in 15 days. Trace the resulting code.

4c. Describe general rules for black-box and white-box program testing.

5a. Write a method that, given the array code of lines of code written by different programmers, returns the total number of lines of code.

5b. In the main method, apply your code to the array consisting of two values 1,000 and 3,000; trace your code, step-by-step, and check that your method returns the correct number 1,000 + 3,000 = 4,000.

6. Give at least two reasons why cheating on a test is not ethical. For example, is it fair to others who do not cheat? Is it fair to those who hire a former student assuming, from his/her good grades, that this student knows how to program? Is it fair to the customers who will rely on the code written by this student? Give detailed explanations.