CS 1401, Exam #1

Date: Thursday, February 3, 2005
Class section (9:00-10:20 am or 10:30-11:50 am): ______________________
Name (please type legibly, ideally in block letters): ______________________________________________________________________
UTEP ID # (if you do not remember it, it is OK): ______________________________________________________________________

Many years ago on this day, on February 3, 1783, Spain officially recognized the new North American Republic -- the USA.

1. Any anniversary of a historic event is an occasion to celebrate history. Select at least two of the following events from the history of computing (more for extra credit), describe why this event occurred and how it contributed to the development of computing:

2. February 3 is an occasion for celebration. The US Ambassador to Spain invites his Spanish friends to enjoy paella in a good Madrid restaurant. The bill shows how many people were eating (p), and what was the overall cost c of the paellas. Sometimes, the restaurant owner waives the fee, so the bill comes at c = 0, as if p = 0 people were eating. Describe, step by step, an algorithm that, given a real number c and an integer p, returns the cost of a single paella. Make sure that your algorithm produces an answer even if the owner waived the fee.

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. The Royal Government of Spain, after recognizing the USA, decided to to be prepared to recognize future new countries as well. Write a main method that asks a user for the name of the new country, and then prints the statement:
El Rey d'Espana reconoce la nueva pais de (name of the country). 
For example, for a country of Mexico, the computer should print:
El Rey d'Espana reconoce la nueva pais de Mexico. 

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

BufferedReader countryReader = new BufferedReader(new InputStreamReader(System.in));
the header of the main method is:
public static void main(String[] args) throws IOException

5. After the healthy meal, the waiter at the Madrid restaurant suggests some coffee. You originally wanted cafe con leche (coffee with milk), while your friend decided to try a more exotic cafe con hielo (coffee with ice). So, in the waiter's laptop, the variable whose name is your name has the value cafe con leche, while the variable corresponding to your friend had the value cafe con hielo. After trying to convince each other that your choice was better, you both succeeded, so now, you want cafe con hielo, and your friend wants cafe con leche. Write down a code that would swap the values of these two variables, and explain, step by step, how it swaps them.