CS 1401, Exam #4, TR version

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

November 26, 1607, is the birthday of John Harvard, who founded the Harvard College now known as the Harvard University, one of the top universities in the world.

1. List, in detail, contributions of US scientists to computing. What motivated their discoveries -- e.g., punchcards? computers?

2a. Companies support discoveries because they often bring more profit that what we invested. The profitability of a discovery can be measured by the ratio of its profit to the amount of investment made into this discovery. Write a method named profitability that, given the profit p caused by the discovery and the investment i, returns the corresponding ratio. In your method, throw an exception to take into account situations when the investment is zero.

2b. Throw an additional exception when the investment is negative.

2c. Call (invoke) your method profitability in the main method to compute the profitability of a discovery. Use try-catch in your main method to catch the two exceptions and print the corresponding error messages. On the example when a company earns $10,000,000 profit after an investment of $2,000,000, trace, step by step, how the computer will perform the needed computations, and check that the result is indeed correct.

3a. Define a class Discovery whose objects are discoveries. The description of each discovery should contain its title, the corresponding investment, and the corresponding profit. Your class should contain a constructor method, get- and set-methods, and a method for computing the discovery's profitability.

3b. Use your class in the main method to define a new object computer of type Discovery; assume that it earned the profit of $10,000,000,000 after an investment of $10,000,000. Compute and print his productivity. While you are computing, the profit increased to $20,000,000,000. Use the set-methods to update the values in the corresponding object, and compute and print its updated profitability.

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

4a. Write a method that, given an array of discoveries, returns the title of the most profitable discovery.

4b. Test your method in the main program, by applying it to two discoveries: computer and car; assume that the profit from the car discovery is $100,000,000,000 and the investment was $10,000,000,000. Trace the resulting code.

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

5a. Write a method that, given the array profit of profits from different discoveries made by the company staff, returns the profit from all the discoveries made by the company.

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

6. Give at least two reasons why it is not ethical to use someone's patented idea without paying the proper royalties. For example, is it fair to the author of the original idea? Is it fair to the company that paid money to develop this idea? Is it fair to the users who will suffer from lack of new developments if -- due to lack of profit -- companies will stop investing in them?