CS 1401, Final Exam, TR version

Date: Tuesday, December 9, 2014
Name (please type legibly, ideally in block letters): ______________________________________________________________________

Each problem is worth 10 points, except if indicated otherwise.

Topic: On December 15, 1888, Herman Hollerith installed his famous device for reading and processing data on punchcards.




Question 1:


Question 2:


Question 3:


Question 4:


Question 5:


Question 6:


Question 7:


Question 8:


Question 9:


Question 10:


Total:

1. Explain the role of Herman Hollerith in the history of computing. What was the purpose of the whole project? What is the current status of the company he founded? How did Herman Hollerith influence the field of computing?

For extra credit: Describe one more event from the history of computing, and how this event influenced the field of computing.


2. Herman Hollerith's work was related to processing census data. One of the questions that is answered by the census data is how much the population increased or decreased.

a. Write a method called change that takes as argument the previous population number p and the current population number c, and computes the percent of change, as ((c − p) / p) * 100. Your method should throw an "IllegalArgumentException" if any of the arguments are negative or equal to 0, otherwise it should computes and return the communication time.

b. Write a statement that calls your method on an example.

c. Trace your method call step by step.


3. Once we know, for each state, whether its population increased, decreased, or remained the same, we need to print a report. The following method receives the state's name and the code describing the population change, and prints the corresponding statement. Here, 'i' means that the state's population increased, 'd' means that it decreased, 's' means that it remained the same, and 'u' means that we are still processing this state's data.

 public static void printRecommendation(String state, char code){
  switch (code) {
    case 'i':  System.out.println("The population of " + state + " increased");
             break;
    case 'd':  System.out.println("The population of " + state + " decreased");
             break;
    case 's':  System.out.println("The population of " + state + " did not change");
             break;
    case 'u':  System.out.println("We are still processing data from " + state);
             break;
    default: System.out.println("invalid code");
}
Write an equivalent method that uses if or if-else statements instead of a switch statement.

Which version of the two methods do you prefer? Explain why.


4. Suppose you have an array of Strings named state containing the names of all the states, and an array of double named change (of the same size) containing the percentage of population changes in the corresponding states. Write a piece of code that prints the names of all the states whose population increased (i.e., for which the percentage change is positive).


5. In many applications of computing, it is very important to get all the numbers right, so testing a code is extremely important. Describe at least five general rules for testing software (e.g., it is necessary to test all branches), and explain, on the example of one of the methods you wrote in Problems 2-4, what exactly values you should use when testing this method. (Describe exact values, not just general descriptions like "boundary values".)


6. Define a class State in which each object has three private fields:

Your code for defining the class should contain:

Write a statement that creates an object of type State named "Texas" with the previous population of 25 million and the current population of 27 million.


7. Let us help census workers record the data about different states. Write a method named enterData that returns an array of objects of type State that are created by prompting the user to enter appropriate data. In particular, your method:

For example, if the user wants to enter 2 states, the program creates an array of size 2, then: Then it prompts for the data for the second state, creates another object and store it at index 1 of the array.

Reminders

To create a Scanner: Scanner input = new Scanner(System.in);
To read an integer value: i = input.nextInt();
To read a String: s = input.nextLine();


8. You want to appropriately write and test your enterData method.


9. Today is 12/09/14. Use the general algorithm that we learned in class to transform 12, 9, and 14 into binary code, add these numbers in binary, and transform, step-by-step, the resulting binary number back into decimal; you should get 35.

For extra credit:


10. A recent article in New York Times advises people to use inspirational passwords like "IQuitSmoking" or "IExercise". The author's experience is that consistently typing such passwords inspired him to quit smoking and exercise more.

a. Is this an ethical idea? Give at least one argument as to why some may think it is acceptable, and at least one argument as to why some may think otherwise -- what potential harm can these passwords do for this person and for others (more arguments for extra credit).

b. Explain the difference between what is ethical and what is prohibited by laws and/or regulations.