CS 1401 Introduction to Computer Science
Fall 2012 Final Exam, TR 12-1:20 pm class section, December 11, 2012

Name: __________________________________________________________

Background: On this day, in 1972, exactly forty years ago, astronauts from Apollo-17 mission landed on the moon. This was the last lunar landing.

1. Apollo-17 spaceship used primitive computers, in which only integer arithmetic operations were hardware supported. To test a computer, astronauts:

Help the astronauts by computing, step-by-step, the value of the following expression (as Java would compute it):
3 / 2 / 2 + 3 / (2 / 2).

2. Each Apollo mission considered several possible landing sites. For each site, scientists estimated how interesting this site will be, while engineers estimated how difficult it will be to land in this site. The Mission Control then selected a site for which the difference between the interest score and the difficulty score is the largest. Write a method that, given two numbers, returns their difference.

3-5. Let us first consider the case when there are three possible landing sites. All these values are given.

6. We may have more than three possible landing sites. In this case, it is reasonable to store the scores of different sites in two arrays: Write a method that, given the two arrays interest and complexity, returns the index i for which the difference interest[i] − complexity[i] is the largest. Trace your method on the example of the following two sites:

7. To compute the speed of the spaceship, the program divided the distance d by the time t that it took to travel this distance. Define a Java method velocity(double d, double t) that computes this velocity. Use exceptions to make sure that when we apply this method to the case when t = 0, we get a meaningful error message. What is the main advantage of exceptions?

8-9. As the Apollo-13 flight has shown, spaceflights are risky. To help astronauts, Mission Control prepared a manual describing what to do if each components of the spaceship is malfunctioning. The instructions are placed in an array instructions, with elements instructions[0], instructions[1], ... The names of the corresponding components are stored, in alphabetic order, in the array names. Given the name of the component, we need to find its index i in the array names, and then print the corresponding instruction instructions[i].
  public static int binarySearch(String[] nam, String comp){
    boolean found = false; int lower = 0; int upper = a.length - 1;
    int mid = 0;
    while(!found && lower <= upper){
      mid = (lower + upper) / 2;
        found = true;
      else if (nam[mid].compareTo(comp) < 0}{
        lower = mid + 1;
        upper = mid - 1;
      return mid;
      return -1;
Here, nam[mid].compareTo(comp) < 0 means that the string nam[mid] precedes the desired string comp in the alphabetic order.

10. Design a class Astronaut for describing astronauts. Each object of this type should contain three fields: the astronaut's name, age, and the number of training hours. Do not forget to add a constructor method and accessor ("get") and modifier ("set") methods. In the main program, create a new object describing you yourself as an astronaut.

11. Let us design a dialog program to help astronauts report possible spaceflight problems. This program should: The program should record these descriptions into an array problems: The program should also count the number of reported problems and record it into the variable numberOfProblems.

12. Describe the contribution of Ada Lovelace to computing.
For extra credit: describe one or two more events from history of computing.

13. Instead of buying software (like Windows) or music, some students copy this software or music from their friends.