## 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 =
0.9.

```
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"):
• WallaceAndGrommit valid

• Wallace-Grommit not valid: a Java name cannot have - inside

• \$1.50 not valid: a Java name cannot have . inside

• \$30 valid but not recommemded, since it has a \$

• double not valid: reserved word

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{
```title = person + " and " + dog;