SCIENCE SEMESTER
1 FINAL EXAM
What kind error occurs when you use the wrong formula to calculate the
area of a circle? - ANSWERS-Logic error. This is because the machine
compiles and has a valid value, but the answer is not correct because of
the equation in the program.
What kind of error occurs when you misspell a Java keyword or forget a
semicolon? - ANSWERS-Compiler error. This is because there is an
error in syntax.
What kind of error occurs when you try to send a Bug outside of a grid
in GridWorld? - ANSWERS-Runtime error. A program has to do 2
things when it is run by the user, compile and run. When moving the
bug, it gives a value and passes through the compiler. The value is
technically valid because it is a coordinate, so that means the compiler
can let it pass through. This can happen when you put in a correct value,
but it is out of the range of possible values. Imagine going to the grocery
store and you want to go to aisle 6, but there are only 5 aisles. You can
head towards "aisle 6" thinking it exists, but once you get there you
realize it's not a valid value. Basically, it is a logical value, but is it not
possible to get to.
END OF
PAGE
1
, AP COMPUTER LATEST
SCIENCE SEMESTER
1 FINAL EXAM
When you compile your Java program, what is produced besides the
output? - ANSWERS-A bytecode file. The *.class file is bytecode. It is
not directly executable. It is translated by the JVM at runtime.
What are some examples of primary memory? - ANSWERS-RAM
(Random Access Memory). It is volatile, so if the power shuts off, the
memory stored within it is not saved.
What are some examples of secondary memory? - ANSWERS-Hard
drive, CD-ROM, Flash drive, etc. These do not need power in order to
continue to store memory.
What are some examples of high-level languages? - ANSWERS-Java,
Pascal, C++, COBOL, Fortran, etc.
What are some examples of low-level languages? - ANSWERS-
Assembly language, machine code
What is the numeric value of the following expression?
Math.min(Math,pow(2,3),7) - ANSWERS-7
END OF
PAGE
2
, AP COMPUTER LATEST
SCIENCE SEMESTER
1 FINAL EXAM
First, it will call Math.pow, which values to 2^3 which values to 8. 8 is
bigger than 7, so 7 is the min.
Operators
What is stored in result after the following statement?
double result = 35 % 40; - ANSWERS-35.0
% is modulus, which means the answer is the remainder if the two
numbers were divided. Because 35 is less than 40, the remainder is 35. It
is also stored as a double, so you need to include the decimal point.
What is stored in result after the following statement?
double results = ; - ANSWERS-6.0
Because neither 19 or 3 are doubles or are cast as doubles, the equation
is first executed and returns a whole number and because it is stored as a
double, there needs to be a decimal point included.
You can store an int in a double because it is a widening conversion, and
Java will except it. Vice versa results in a loss of precision and will
return a compiler error.
END OF
PAGE
3