CS 1401, Exam #1

Date: Friday, September 15, 2006, 9:30 am
Name (please type legibly, ideally in block letters): ______________________________________________________________________

1. History of computing:
(a) Where does the word "algorithm" come from?
(b) Briefly describe Francois Viete's contributions to computing.
(c) For extra credit: describe one more event from the history of computing.

2. As you may know, this year, the main Independence Day celebration was moved from Mexico City to the city of Dolores Hidalgo about 170 miles away. As a result, some people who planned to celebrate in Mexico City need to travel further away. Suppose that you know the exact distance, you know how much miles per gallon your car makes, and you know the price of a gallon of oil in pesos (for simplicity, let us avoid kilometers and liters). Describe, step-by-step, an algorithm that would compute the overall price of gasoline needed for the trip. For example, if the distance is 200 miles and your car make 25 miles per gallon, then it needs 200/25=8 gallons. At a price of 30 pesos per gallon that would mean spending 8 x 30 = 240 pesos.

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. Write a main method that asks a person for the distance to travel, for the amount of miles per gallon that his or her car takes, and for the price of gas, and then computes and prints the statement:
 For gas, you pay $(amount). 
(Do not worry about formatting.) For example, if your estimates cost is 240 pesos, the computer should print:
 For gas, you pay $240.0. 

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

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

6. We hope that you did well on this test. Congratulate yourself on the job well done by writing down a line of code that, given a string yourName (that contains your name), places the corresponding congratulations into a variable congratulations. For example, if your name is Maria, the contents of the string congratulations should be "Congratulations, Maria, on your first CS exam!".