Computer Science 157 – Spring 2002

02/20/02                 Mid Term Test # 1                               Test Form A

 

Name:

 

Instructions:

                Answer ALL questions on the answer sheet provided.

                Hand in TEST, Answer Sheet, and Help Sheet, each with your name on it.

                Remember to put the letter of your test form on your answer sheet.

                Please ask any clarifying questions you have (come up).

 

Multiple Choice (4 points each)

 

1.             A bit can have __________ different values.

A.                  2     

B.                   10   

C.                   100 

D.                  256

 

2.             A(n) __________ occurs when a program has a grammatical mistake like missing punctuation.

A.                  syntax error  

B.                   run-time error               

C.                   logic error     

D.                  hidden error

 

 

Completion (3 points each)

 

3. The solution to any problem involves performing an ordered series of actions. The planned step-by-step sequence of actions is called a(n) ________. Such an ordered procedure occurs in everyday life as well as in computer problem-solving.

 

4. A(n) ________ is enough memory / disk space to hold 8 binary digits. This is used as a unit of measure for memory and disk space.

 

5. ________ language is directly understandable and executable by the computer. It consists entirely of 1’s and 0’s. Each computer processor has its own version of this.

 

6. Modern programs frequently have a(n) ________, where the user interacts with the program via windows, dialog boxes, buttons, mouse etc, instead of more traditional programs which are “text” based – all letters and numbers on a line.

 

 

Short Answer (points as shown)

 

(6 points)

7. Why is it important to include comments explaining your program?

 

(6 points)

8. Why is it a good idea to use named constants instead of unnamed constants?

 

 


Valid/Invalid (4 points each)

For each, tell whether valid or invalid. If invalid, tell why!

Generally they are taken out of context, we assume that valid context surrounds them (e.g. inside a program, variables declared etc)

 

9.

int  Val2;

 

10. 

  int z = 2;

  int x = 6;

  z + 4 = x;

 

 

11.

  int x = 2;

  int y = 9;

  System.out.println ( "This is the first number "  +  x

        +  " This is the second number "  +  y );

 

12.

  int x = 11;

  int j;

  if x < 13 {

     j = x + 1;

    }

 

 

Doing and Understanding: (points as shown)

 

 

(6 points)

13. What is displayed by the following code fragment:

 

  int x = 15;

  int y = 10;

  int z = 0;

  z = y;

  y = z;

  z = x;

  System.out.println (“x:  “ + x  + “  y:  “  +  y + “  z: “ + z);

 

 

 (8 points)

14. What is displayed by the following code fragment:

 

  int a = 8;

  int b = 7;

  if (a > b) {

     a--;

     b++;

    }

  else {

     a++;

     b--;

    }

  System.out.println("a: “ + a + “  b: “ +  b);

 

 

(8 points)

15. What is displayed by the following code fragment:

 

  int i = 9;

  switch (i) {

    case 1:

    case 2:

    case 3:

    case 6:

         System.out.println ( "1" );

         break;

    case 4:

    case 5:

    case 7:

         System.out.println ( "2" );

    case 8:

         System.out.println ( "3" );

         break;

    default:

         System.out.println ( "4" );

    }

 

 

(10 points)

    16. What is displayed by the following code fragment?

 

int number = -5;

while (number < 7) {

    System.out.println(“number:  “  +  number);

    number += 4;

}

System.out.println(“done”);

 

 

Writing Code (points as shown)

 

(5 points)

17. Write  statement(s) in Java that will convert a Fahrenheit temperature to the corresponding Celsius temperature. The formula is:

   Celsius = 5/9 (Fahrenheit - 32)

 

 

 (15 points)

18. A software company charges license fees based on the following criteria. Start with a base charge of $100. Add $20 for every user, up to a maximum of $200. Add $100 if the purchaser has profits of greater than $100,000. Assuming that the variables (numUsers, profit) have been declared and given values (through System.out.println/SavitchIn.readLineInt combinations), write statements that will calculate a total license fee, and display the fee.