COE 211 – Computer Programming
COE 211 – Computer Programming
Welcome to
Midterm Examination#1
Tuesday December 19, 2006
Instructor: Wissam F. Fawaz
Name: _______________________
Student ID: ________________
Instructions:
1. This exam is Closed Book. Please do not forget to write your name and ID on the first page.
2. You have exactly 60 minutes to complete the six required problems and the one extra credit problem (worth 8 points).
3. Read each problem carefully. If something appears ambiguous, please write your assumptions.
4. Do not get bogged-down on any one problem, you will have to work fast to complete this exam.
5. Put your answers in the space provided only. No other spaces will be graded or even looked at.
Good Luck!!
Problem 1: Quick questions (10 minutes) [15 points]
1) Match each word on the left with the best definition on the right [6]
Object _C_ A. A description of a set of similar objects
Class_A_ B. A simple, built in entity, including char, int, float
Compiler_D_ C. An instance of a class
Java_E_ D. A program that translates high level programs
into machine language
Variable_F_ E. A high level object oriented programming
language
Primitive type_B_ F. A named storage location for information
2) Which package would you import if you needed to use the Scanner class in your Java program? [1]
java.util
3) What is one way to tell the difference between a class type and a primitive type just by looking at the name of the type? [2]
Class types start with capital letters and primitive types start with lower case letters
4) Write a Boolean expression that is true only when the variable x is between 0 and 10. Please note that your expression should be true when x equals 0, and false when x equals 10. [2]
(x >=0) && (x < 10)
5) True or false: the = operator can be used in a Boolean expression to test whether or not two values are equal. [1] false
6) True or false: the String class part of the java.lang package can be used without an explicit import declaration. [1] True
7) True or false: a Java program can have two different variables with the names aVariable and avariable. [1] True
8) True or false: every variable in Java must be declared and then given a value before it is used. [1] True
Problem 2: Evaluating Java expressions (5 minutes) [15 points]
Evaluate each of the following Java expressions, entering their values in the boxes provided. You may use the area outside the boxes for calculation.
Example: 3 == 2
a) 3 + 2*2 + 1.5 [1]
b) 5/4 [1]
c) 5.0/4.0 [1]
d) 1234567 % 100 [1]
e) “Hi” + “There” [1]
f) (2>3) && (5 y) System.out.println(x + “ is greater than ” + y);
else if (y > x) System.out.println(y + “ is greater than ” + x);
else System.out.println(x + “ is equal to ” + y);
}
}
2. Write a program that calculates the factorial of a given entry value. [5]
Note: Factorial value of n is n*(n-1)*(n-2)*(n-3)* … *1
Example Result:
Enter a Number: 5
5! = 120
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
int x, fact = 1;
Scanner scan = new Scanner (System.in);
System.out.println("Enter an integer: ");
x = scan.nextInt();
for (int i =2; i ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- high school computer programming curriculum
- free computer programming for beginners
- computer programming languages
- computer programming languages pdf
- what is computer programming pdf
- computer programming history timeline
- top 20 computer programming languages
- basic computer programming pdf
- list of computer programming language
- computer programming pdf
- computer programming for beginner
- computer programming for middle schoolers