CS 1401, Exam #1

Date: Thursday, February 9, 2006
Name (please type legibly, ideally in block letters): ______________________________________________________________________

1. Briefly describe Ada Lovelace's and Alan Turing's contributions to computing. How did the invention of logarithms help computing? For extra credit: describe one more event from the history of computing.

Ada Lovelace was the world's first programmer. She wrote "programs"
for the Babbage's computing machine.

Alan Turing designed a general model of computation; during the
Second World War, he helped design a specialized computer nicknamed
"Bomb" that successfully decoded German military codes.

Logarithms made computations easier because they enabled to reduce
multiplication to an easier operation - addition. The use of
logarithms in computing is based on the fact that
log(a*b) = log(a) + log(b). So, to compute a*b, we can do the following:

1) find log(a) and log(b),

2) add these two logarithms, thus computing s = log(a)+ log(b); and

3) find a number whose logarithm is equal to this sum s.

This number will be exactly a*b.

This idea formed the base of a slide rule, which for several
centuries was the main computational tool of engineers.

2. At UTEP Union, one burrito costs $1.50; if you buy more than 10, you get a 10% discount. For example, 5 burritos cost 5 x $1.50 = $7.50; 20 burritos cost (20 x $1.50) * (1-10/100) = $30 * 0.9 = $27. Describe, step-by-step, an algorithm that, given the number of burritos, returns the total price of these burritos.

1) First, multiply $1.50 by the number of burritos.

2) Check if the number of burritos is 10 or smaller.

   a) If yes, return the number computed on Step 1 as the desired answer

   b) If no, multiply the number computed on Step 1 by 1 - 10/100 =

3. For each of the following sequences of symbols, describe which can be valid Java identifiers and which cannot be; if you believe they cannot be, briefly explain why (e.g., "is a reserved word" or "does not start with a letter"):

4-5. Burritos again, this time without a discount. Write a main method that asks a student for the number of burritos, and then computes the total and prints the statement:

For (number) burritos, you pay $(amount).
For example, if you ordered 5 burritos, the computer should print:
For 5 burritos, you pay $7.50.

Reminder: to read strings, you can define the input object as follows:

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
to convert the string into a real number, you can use the method
Double.parseDouble( )
the header of the main method is:
public static void main(String[] args) throws IOException{

public static void main(String[] args) throws IOException{
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Please enter the number of burritos");
  String reads = in.readLine();
  int burritos = Integer.parseInt(reads);
  System.out.println("For "+ buritos+" burritos, you pay $" +
    1.50 * (double) burritos+ ".";

6. Due to the success of the new movie "Wallace and Gromit", many Hollywood studios decided to make similar movies about folks and their dogs. Write down a line of code that, given two strings person (that contains the person's name) and dog (that contains his or her dog's name), places the corresponding movie title into the variable movie. For example, if the contents of the string person is Fred, and the contents of the string dog is Scooby-Doo, then the resulting movie title is "Fred and Scooby-Doo".

title = person + " and " + dog;