CS 1401, Exam #1, MW 12-1:20 version

Date: Wednesday, September 18, 2013
Name (please type legibly, ideally in block letters): ______________________________________________________________________

1. On September 18, 1998, the International Corporation for Assigned Names and Numbers (ICANN) was started, an organization that controls the naming of websites.

For extra credit: describe one more event from the history of computing.











































2. 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"):












































3. The following formula enables us to compute the area a of a right triangle with sides x and y:
      1
  a = - xy
      2
Assuming that x and y are already placed in the corresponding variables of type double, write a Java code statement for assigning the corresponding value to the variable a of type double. Explain, step-by-step, which arithmetic operations will be performed first, which next, etc., and trace the computations on the above example. Describe two different ways to avoid getting 0 as the result of evaluating 1/2. Explain what happens if you simply write xy in your Java code.















































4-5. To register a website for several years, you need to pay a per-year registration fee. For simplicity, let us take $35 as this fee. Write the main method which asks the user for the URL of the website, asks for how many years we want to register this website, and prints a memo describing the price. For example, if we want to register CS website http://www.cs.utep.edu for 3 years, your program should print the following message:
From: ICANN

To register your website http://www.cs.utep.edu, you need to pay
$35 X 3 = $105.
Declare 35 as an integer constant, so that it will be easy to change if needed.

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

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





































6. Suppose that would like to add 2 to the number of years. If the number of years is stored in the integer variable years, which of the two lines of code leads to a correct increase: If originally, before each line, we had 3 years, explain what will happen after each of these lines is implemented by Java. What is a clearer way (different from those above) to add 2 to the variable years?