CS 1401, Exam #2
Date:
Thursday, March 2, 2006
Class section
(9:00–10:20 am or 10:30-11:50 am): ____________________
Name (Please
type legibly, ideally in block letters):
_________________________________________________________________________
Athletic events of the Torino
Winter Olympic games were all held indoors. However, weather was a factor at
the closing ceremonies, last Sunday at the Stadio Olimpico. According to USA Today, the average February
daytime high in
1. Write a method named celsiusToFahrenheit that converts temperature readings
from Celsius to Fahrenheit degrees. Trace your method on the example of 100 ^{o}C and show that your method correctly computes
the value of 212 ^{o}F.
Use the conversion equation:
Fahrenheit = |
_{_9_} |
Celsius + 32 |
^{5} |
2. If the variable freezePoint has the initial value 32, and we run the
following sequence of statements, what will be the resulting values of the
variables cool, reallyCold, and boiling?
int cool = freezePoint * (int) 1.2;
int reallyCold = cool /
10;
double boiling = 7.0 * freezePoint;
reallyCold--;
What is the advantage of
using reallyCold--
instead of reallyCold = reallyCold - 1?
3. The news about the next
Olympic Games inaccurately cited
4. Yevgeny
Plushenko won the gold medal in the men’s figure
skating competition at the Torino Olympic Games. Suppose that we stored the
points obtained by two skaters in variables firstPlace
and secondPlace. Write a code
segment that will correctly sort these values, i.e., make sure that firstPlace has the most points by swapping the values of
the variables if needed.
5. The top three competitors
of the women’s giant slalom in the Torino Olympic Games were Julia Mancuso from
the U.S., Finland’s Tanja Poutinanen,
and Sweden’s Anna Ottoson. Write a method usGold that, given the overall time for Julia, Tanja, and Anna, returns true or false
depending on whether Julia obtained the fastest time.
6. What are the reasonable
test cases for the method that you developed for Problem 5? Explain your
answer.
7.
Remember that:
·
The circumference
of a circle is 2 * PI times its radius.
·
The area of a
circle is PI times the radius squared (use the corresponding method from the
Math package).