CS 1401, Exam #1

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

1. History of computing:
(a) Describe the contribution of ancient Egyptians to computing.
(b) How did the invention of zero make computing easier?
(c) For extra credit: describe one more event from the history of computing.

(a) Egyptians invented computational geometry: they needed it to
recover the borders between plots of land that were annually flooded
by Nile.

(b) invention of zero made possible the existing positional system in
which all operations are the same, no matter whether they are applied
to ones, tens, or hundreds. Multiplying 26 by 13 by hand may be somewhat
difficult, but try multiplying XXVI by XIII in Roman notations!

2. As you may know, today, El Grito is celebrated on campus - just as we are working on this test. To make the participants more comfortable, the University decided to bring benches for people to sit. Suppose that you know how many people plan to come, you know the percentage of people who prefer to sit, and you know how many people can sit on a single bench. Describe, step-by-step, an algorithm that would compute the necessary number of benches. For example, if we expect 1,200 folks and we know that 40% prefer to sit, then we need siting places to accomodate 1,200 x (40/100)= 480 people. If each bench sits 10 people, this means that we need 480/10=48 benches.

1) Multiply the number of folks and the percentage of those who prefer
to sit, and divide the result by 100 - thus computing the number of
sitting places.

2) Divide the number of sitting places by the number of seats on a bench.

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 user for the number of people planning to attend, for the percentage of those who want to sit, and for the number of people that can sit on one bench, and then computes and prints the statement:

 For El Grito, we need (amount) benches. 
For example, if your estimates number is 48 benches, the computer should print:
 For El Grito, we need 48 benches. 

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){

public static void main(String[] args){
  Scanner key = new Scanner(System.in);
  System.out.println("Type in the expected number of folks.");
  int folks = key.nextInt();
  System.out.println("Type in the percentage of those who want to sit.");
  double percentage = key.nextDouble();
  int places = folks * (percentage / 100.0);
  System.out.println("Type in the number of seats on a bench.");
  int seats = key.nextInt();
  int benches = places / seats;
  System.out.println("For El Grito, you need " + benches + "benches");

6. After a hard-working week, you deserve some rest. Help yourself relax by writing down a line of code that, given a string yourName (that contains your name), places a wish for you to have a nice weekend into a variable wish. For example, if your name is Beatriz, the contents of the string wish should be "Dear Beatriz, have a nice weekend."
String wish = "Dear " + yourName + ", have a nice weekend.";