CS 1401, Exam #3, TR version

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

On November 7, 1867, the famous scientist Marie Curie was born. Dr. Curie, a French-Polish physicist and chemist, is famous for her pioneering research on radioactivity. She was the first woman to win a Nobel Prize, the only woman to win in two fields, and the only person to win in multiple sciences.

1a. Write a method named energy that, given the power p of a radioactive source (in Watts W) and the time t (in seconds) that it operates, returns the amount of energy produce by this source. (Hint: power is energy per unit time, so energy is power times time).

1b. Call (invoke) your method energy in the main method to compute the total energy produced by the 100 Watt source during 20 seconds. You do not need to write the entire main method, just the part that assigns values to the corresponding variables power and time 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 Nobel whose objects are different Nobel prize winners. The description of each winner should include his/her name, birth year, and the year in which he/she was awarded the prize. Your class should contain a constructor method, get- and set-methods, and a method for computing the age at which the scientist received the Nobel Prize as the difference between the two years.

2b. Use your class in the main method to define a new object curie of type Nobel. Marie Curie was born in 1867, she received her first Nobel Prize in 1903. Compute and print her age at the time of receiving the Nobel Prize; then, replace 1903 with the date of her second Nobel Prize (1911) and compute and print her age at the time of the second prize.

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














































3a. Write a piece of code that, given an array birthYear of birth years and the current year curYear, computes and prints the ages of these students. Assume the arrays have been declared, initialized, and that they have the same length.

3b. To check the correctness of the code you wrote in Part 3a, write a piece of code that defines a new array birthYear with elements 1990 and 1993 and a new value curYear equal to 2013.

3c. Trace step-by-step how the piece of code you wrote in Part 3a will compute the corresponding ages.


















































4a. Write a method that, given an array a of ages of different students and the array n of their names, finds the name of the youngest student. Assume the arrays have been declared, initialized, and have the same non-zero length.

4b. To check the correctness of your method, write a piece of code that defines new arrays age consisting of 3 elements 23, 20, and 25, and names with elements K, L, and V.

4c. Trace step-by-step how the piece of code you wrote in Part 4a will find the name of the youngest student. Hint: L is the youngest, he is only 20 years old.

















































5a. Describe what is white-box and black-box testing.

5b. Describe the main rules for testing.