ITEC 120 Exam 1
2008.Feb.15, v1.0

“They say it takes hardship now
 to help you love all the rest 
sometimes underneath the load
is where I show my best...”
	Pleas -- Widespread Panic

Name :  _____________________

Short Answer
1.) In Java, 2 * 2000000000 (two times 2 billion) is ...
   (a) 4000000000 (4 billion as an int)
   (b) 4.0e9 (4 billion as a double)
   (c) an int less than zero
   (d) an error (an "overflow exception")
   (e) 3999999998 (or some int which is close to 4 billion)
   (f) 3.999999998e9 (or some double which is close to 4billion)

2.) The + operator can refer to either of two different operations. What are they?

3.) 	In Java, =   is called ___________

  	   In Java, == is called ___________

   	   In Java, !=  is called ___________

  	   Which one(s) of the above must you use to initialize a local variable? ________

4.) What are two differences between local variables and named constants?

5.) What is a magic number?  How can we remove magic numbers from our code?

6.) (a)  True/False: x can be a parameter            (c)  True/False: x can be an argument
      (b)  True/False: 5 can be a parameter            (d)  True/False: 5 can be an argument

7.) The region of code where we can use a parameter, variable, or named-constant is called its

      __________, and is denoted in code by ____________.

8.) For each of the following name the Java type best suited to represent it:

	a.) whether it is below freezing      __________

	b.) the temperature on the moon   __________

	c.) the number of leaves on a tree __________

	d.) your credit card number             __________

9.) What does the keyword "this" do?    When do we use it?

10.) What is "The First Law Of Programming"?  Name one way we can obey the first law.

Short Code:
1.) Fill in the following test cases:
	/** A function computing a mystery result.
      * Tests (supposing that `m` is an instance of this class):
	 *   m.mystery(                     ) = true
	 *   m.mystery(                     ) = false
	 */
	boolean mystery(boolean a, boolean b)
	{
   		return (a && !b) || (!a && b); 
	}

2.) Suppose class Muppet contains a function whose signature is:
	 int meep(String s, boolean b)
      If beaker is an instance of Muppet and n is an int which has been initialized, then:
	a.) Call meep, passing in "Bunsen" and true.

        __________________________________________________________
	b.) Call meep, passing in the empty string and whether n is larger than 5.

        __________________________________________________________
	c.) Call meep, passing in the empty string and false, and then multiply the result by 2.

        __________________________________________________________

3.) Fill in the test cases and complete the function:
    /** Determines whether a number is odd (not even).
	* @param n A number to test.
	* @return whether n is an odd(not even) number.
	*   z.isOdd(    5    ) = true
	*   z.isOdd(         ) = 
	*   z.isOdd(         ) = 
	*/
	_________ isOdd( ________  _______  )
	{

	}
Hint: The remainder after dividing any int by 2 ("mod 2") is either 0 or 1.  (Your solution might be one line, or about three.)

4.) 	a.) Declare a variable to store the cost of Virginia peanuts (in $/pound). 

               __________________________
	b.) Initialize that variable to a reasonable value of your choice.

               __________________________

Code:
An airport offers short term parking at $1.50 for every hour you are parked.  After much complaining they allow you to park for the first 15 minutes for free (a grace period), but after that any part of an hour is rounded up.  For the following questions, answer by filling in the code for a class ParkingLot below.

1.) Declare and initialize at least 2 named constants which correspond to the numbers mentioned in the problem statement.

2.) Complete the tests and write a function named billableHours which takes in a number of minutes and returns how many hours to bill the customer.

3.) Complete the tests and write a function name amountOwed which takes in a number of minutes and returns how many dollars the customer owes.  You may assume that you have a correct solution for #2, when writing #3.

class ParkingLot {

	/** Compute the number of billable parking hours.
	 * @param minutes The total minutes parked.
	 * @return the number of billable hours.
      * Tests (assuming 'lot' is an instance of ParkingLot):
	 *   lot.billableHours(   5  ) = 0
	 *   lot.billableHours(      ) = 
	 *   lot.billableHours(  65  ) = 1
	 *   lot.billableHours(      ) = 
	 */

            //   (turn the page, for amountOwed)

	/** Compute the cost for parking.
 	 * @param minutes The total minutes parked.
	 * @return the number of dollars the customer owes.
      * Tests (assuming 'lot' is an instance of ParkingLot):
	 *   lot.amountOwed(    5  ) = 0
	 *   lot.amountOwed(       ) = 
	 *   lot.amountOwed(   65  ) = 1.5
	 *   lot.amountOwed(       ) = 
	 */

}