## CS 1401, Exam #1, 11:30 am version

Date: Friday, September 21, 2007
Name (please type legibly, ideally in block letters): ______________________________________________________________________

1. History of computing:
(a) How is Java - the language that we study in this class - different from previous programming languages?
(b) Briefly describe the importance of logarithms for computing.
(c) For extra credit: describe one more event from the history of computing.

```

```
2. Exactly 70 years ago, on September 21, 1937, J. R. R. Tolkien published The Hobbit book, which started the Lord of the Rings series. To celebrate, the students decided to rent a movie theater and watch all the Lord of the Ring movies. Describe, step-by-step, an algorithm that would allow to compute how much we need to collect from each student to cover the costs. As part of this algorithm, you should ask for the cost of renting the movie theater, and the cost of popcorn and drinks per student. For example, if renting a movie theater costs \$1,000, popcorn for each student costs \$4, and the drinks \$2, then the cost of the party for 100 students is \$1,000 + 100 * (\$4 + \$2) = \$1,600. Thus, each student has to pay \$1,600 / 100 = \$16.
```

```
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"):
• King Aragorn

• KingAragorn!

• KingAragorn

• double

• popcornIs\$4PerPerson

```

```
4-5. Write a main method that asks a person for the cost of renting a movie theater, the cost of popcorn per student, the cost of drinks per student, the number of students, and the name of the contact person, and then computes and prints the statement:
```Dear (name here),

For your Hobbit party, you need to collect \$(amount) per student.
```
(Do not worry about formatting the amount.) For example, if Sheline John is a contact person for the party of 100 in which renting a movie theater costs \$1,000, the popcorn for each student costs \$4, and the drinks \$2, then each student has to pay \$16, so the computer should print:
``` Dear Sheline John,

For your Hobbit party, you need to collect \$16.00 per student.
```

Reminder: to read from the keyboard, you can define the reader as follows:

```Scanner keyboard = new Scanner(System.in);
```
the header of the main method is:
```public static void main(String[] args){
```

```

```
6. To make the Hobbit party a great memory, the organizer decided to give every student an official certificate. To design such certificates, write down a line of code that, given a string name (that contains the name of the person who will receive this certificate), places the message "This certificate confirms that (name here) participated in the 2007 Hobbit party." into a string message. For example, for a student whose name is Vladik, the contents of the string message should be "This certificate confirms that Vladik participated in the 2007 Hobbit party."