Download Review Final Exam from CP1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Computer Programming I
Fall 2008 - Final Examination
True/False – Answer A for true; or B for false
1) The keyboard is an example of computer hardware.
2) Both software and data are examples of computer software.
3) The CPU is the primary area for storage and data in the computer.
4) Most CPU’s process programs and data directly from long term storage.
5) The keyboard, mouse, and computer screen are all examples of Input/Output
devices.
6) All software and data is stored as a series of 1’s and 0’s in the computers that
we use in this class.
7) Java is a case-sensitive language, which means that Average, average, and
AVERAGE will all reference the same identifier.
8) Code placed inside of comments will be executed like every other statement
in a JAVA program, but they do not affect the output.
9) A variable of type Boolean has only two valid values: true or false
10) The statement x = x + 1 increases the value of x by 1
Multiple choice. Please choose the best single answer for each question.
11)Which of the following are things that an operating system controls?
a. Machine activities
b. User interfaces to the computer
c. Manages the use of memory
d. Manages the use of the CPU
e. All of the above are controlled by the operating system
12)Which of the following describes data that is broken down into pieces and
stored as numbers
a. Analog
b. Digital
13)What is the maximum number of combinations that can be stored with 8 bits
of information using base 2?
a. 8
b. 16
c. 32
d. 128
e. 256
14) What is the largest positive integer that can be stored with 8 bits using base
2?
a. 7
b. 15
c. 31
d. 127
e. 255
15) A JAVA program is best classified as
a. hardware
b. software
c. storage
d. a CPU
16) Which keyword is used as the first word in the declaration of a constant?
a. int
b. double
c. constant
d. final
17) What is the result of the operation 30%4?
a. 2
b. 3
c. 4
d. 7
18) Which of the following is not an example of an assignment statement?
a. total = 32;
b. count = count + 1;
c. value = (min/2)*lastValue;
d. int total;
e. sides = 10;
19)Which of the following will make a new String object?
a. String word = new String(“ “);
b. word.length = String;
c. String new = String.word;
20) Which of the following is NOT a correct way to format a comment?
a. // This is a comment
b. /* This is a comment */
c. */ This is a comment /*
d. //*****This is a comment************************//
21) Which of the following correctly demonstrates initializing a variable?
a. int myVariable;
b. int myVariable = 4;
c. int myVariable = “ “;
22) What type of error occurs in a program that incorrectly computes the
amount of an employee’s paycheck?
a. a syntax error
b. a run-time error
c. a logic error
23)Which of the following class names follows JAVA naming conventions?
a. StoreCustomer
b. Store Customer
c. storeCustomer
d. STORE_CUSTOMER
24)Which of the following names for a variable follows JAVA naming
conventions?
a. StoreCustomer
b. Store Customer
c. storeCustomer
d. STORE_CUSTOMER
25)Which of the following would be best (following naming conventions) for a
variable that contains the current value of a stock?
a. theCurrentValueOfThisStockIs
b. currentStockVal
c. currentstockvalue
d. csv
26)Assuming game is an instance of the Random class, which statement below
will generate a random number between1 and 10 (this includes the numbers
1,2,3,4,5,6,7,8,9,10)?
a. randomNumber = game.nextInt (9);
b. randomNumber = game.nextInt (10) + 1;
c. randomNumber = game.nextInt (11);
d. randomNumber = game.nextInt(10) – 1;
27)Which of the following symbols need an associated “closing” symbol in a
JAVA program?
a. {
b. [
c. (
d. all of the above need a “closing” symbol
28)What type of error will occur if you forget a semicolon on a statement where
it is required?
a. syntax
b. run-time
c. logical
d. no error
29)Which of the following is the correct description of a named memory area
that temporarily stores data that you can change while the program is
running?
a. constant
b. assignment statement
c. variable
d. import declaration
30) A word that has special meaning in JAVA and cannot be used for any other
purpose is called:
a. a class word
b. a reserved word
c. an object
d. a method
Use the following class definition to answer questions #31-33
public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
31.
What is printed by the program?
a) Here
There Everywhere But not in Texas
b) Here
There Everywhere But notin Texas
c) HereThere Everywhere
But notin Texas
d) Here
ThereEverywhere
But notin Texas
32.
Is the syntax for the main method statement in the program correct?
a) Yes
b) No
33.
How many lines of output will be produced by this program?
a) 1
b) 2
c) 3
d) 4
34
A reasonable comment for this program might be
a) // demonstrates the differences between print, println and how string
concantenation (+) works
b) // demonstrates the main method in JAVA
c) // outputs the message “Here There Everywhere But not in Texas”
35.
What output is produced by the following statement?
System.out.println (“50 plus 25 in java is“ + 50 + 25);
a) this statement will produce a syntax error
b) 50 plus 25 in java is75
c) 50 plus 25 in java is5025
36.
Which of the following is the correct code to use the Scanner Class?
a) scan = new Scanner;
b) SCANNER SCAN = NEW SCANNER (System.in);
c) Scanner scan = new Scanner (System.in);
d) Scanner scan = old Scanner (System.out);
37.
38.
What is output of the statement System.out.println(x+y); if x and y are int values where
x=10 and y=5?
a) 15
b) 105
c) 10+5
d) x+y
What does the escape sequence \n do?
a) Adds a new line to the output
b) Removes a new line from the output
c) Deletes all letter n’s from the output
d) Highlights all the letter n’s in the output in bold
39.
What is the proper code if you were to ask the user to enter the quantity using the Scanner
class?
a) System.out.print (“Enter the quantity:”);
quantity = scan.nextInt();
b) System.out.print (“Enter the quantity:”);
scan.nextInt() = quantity;
For questions 40 – 42, refer to the class defined below:
import java.until.Scanner;
public class Average
{
public static void main(String[ ] args)
{
int x = 0;
int y = 0;
int z = 0;
double average = 0;
Scanner scan. Scanner scan = new Scanner (System.in);
}
}
System.out.println("Enter an integer value");
x = scan.nextInt( );
System.out.println("Enter another integer value");
y = scan.nextInt( );
System.out.println("Enter a third integer value");
z = scan.nextInt( );
average = (x + y + z) / 3;
System.out.println("The result of my calculation is " + average);
40.
Average computes
a) the remainder of the sum of x, y and z divided by 3
b) the correct average of x, y and z as an int
c) the average of x, y and z as a double, but the result may not be accurate because it is
an int division
d) the sum of x, y and z
41.
What is the output if x = 0, y = 1 and z = 1?
a) 0
b) 0.0
c) 0.6666666666666666
d) 0.6666666666666667
42.
How many variables are in the program?
a) 1
b) 2
c) 3
d) 4
43.
If String name = "Richard M. Daley"; then the instruction name.length(); will return 16.
a) true
b) false
44.
The operators * and + have the same precedence.
a) true
b) false
45.
What will be the result of the following assignment statement?
Assume b = 5 and c = 10.
int a = b * (-c + 2) / 2;
a) 30
b) –30
c) 20
d) –20
46.
What is the meaning of \t?
a) tab
b) tab twice
c) return
d) total
47.
In the following equation, which mathematical procedure would you do first?
X = ((5-8(7+1))^2)*10
a) Addition
b) Subtraction
c) Division
d) Exponentiation
48.
Which primitive data type in Java stores a floating point number(has a decimal point)?
a) Boolean
b) Char
c) Short
d) Double
49. Which of the following is executed when you create an instance of a new class in
your program?
a. the main method
b. a constructor method
c. a static method
50. Which of the following are the structures that are used in structured
programming?
a. static, constructor, main
b. sequence, decision, looping
c. sequence, class, method