CS 1401, Exam #1

Date: Thursday, February 8, 2007
Section (9 am or 10: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 contribution of Ada Lovelace to computing.
(c) For extra credit: describe one more event from the history of computing.

2. As you know, the Valentine Day is coming soon, so flower shops are getting ready. Suppose that a florist charges a certain amount per rose and a certain fixed amount for delivery. A student who orders the roses is not good in calculations, and a young man who helps the florist is not good in calculations either. You need to help them. Describe, step-by-step, an algorithm that would allow to compute how much the delivery will cost. As part of this algorithm, you should ask for the prices and for the amounts. For example, if each rose costs $1 and delivery costs $1.50, then the cost of delivering a dozen roses is 12 * 1.0 + 1.50 = $13.50.

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 price per rose, price of delivery, number of roses, and the name of the client, and then computes and prints the statement:
 Dear (name here), for your Valentine Day delivery, please pay $(amount).
(Do not worry about formatting.) For example, if John orders 12 roses at $1 each and the delivery costs $1.50, the computer should print:
 Dear John, for your Valentine Day delivery, please pay $13.50.

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. Help a florist to write messages which come with the flowers. For that, write down a line of code that, given a string aName (that contains the name of the person who will receive the roses), places the message "Dear (name here), be my Valentine!" into a string message. For example, if the roses are intended for Mary, the contents of the string message should be "Dear Mary, be my Valentine!".