DOC PREVIEW
UVA CS 101 - Midterm 1

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 101 Spring 2007 Midterm 1 Name: _______________________________ Email ID: ________ You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure to look over all the questions and plan your time accordingly. Please sign the honor pledge here: Page 1 ____ / 3 Page 2 ____ / 17 Page 3 ____ / 25 Page 4 ____ / 20 Page 5 ____ / 15 Page 6 ____ / 20 Total ____ / 100 Note: When an integer type is required use int, when a floating-point type is required use double. If we don’t specify an aspect of the problem, you can choose it. Note: If you are still writing on the exam after “pens down” is called – even if it is just to write your name – then you will receive a zero on this exam. No exceptions! 1. [3 points] What lab section are you in? ____ CS 101-E ____ CS 101-2 (lab 8:00–9:15 a.m. Thu) ____ CS 101-6 (lab 2:00–3:15 p.m. Thu) ____ CS 101-3 (lab 9:30–10:45 a.m. Thu) ____ CS 101-7 (lab 3:30–4:45 p.m. Thu) ____ CS 101-4 (lab 11:00–12:15 p.m. Thu) ____ CS 101-8 (lab 5:00–6:15 p.m. Thu) ____ CS 101-5 (lab 12:30–1:45 p.m. Thu) ____ CS 101-9 (lab 6:30–7:45 p.m. Thu) Page 1 of 6CS 101 Spring 2007 Midterm 1 Name: _______________________________ Email ID: ________ 2. [9 points] Consider the following statements in the Java language: Scanner stdin = new Scanner(System.in); double PI = 3.14159; final double centimetersPerInch = 2.54; String input = new String("Wahoos!"); int meaningOfLife = 42; Rectangle square = new Rectangle(2,2); Answer the following as true or false (don’t answer T or F – you need to write the FULL word to get credit). a. PI is a constant Answer: ____________ b. The word stdin is a Java reserved word. Answer: ____________ c. centimetersPerInch is an invalid identifier name. Answer: ____________ d. The word Final can be the name of a variable (notice the capitalization) Answer: ____________ e. String is an object Answer: ____________ f. meaningOfLife is a variable Answer: ____________ g. double is a class Answer: ____________ h. square is a variable Answer: ____________ i. Rectangle is a type Answer: ____________ 3. [8 points] Draw a memory diagram showing what memory looks like after the following four statements: String s1; String s2 = null; String s3 = ""; String s4 = "CS101"; Page 2 of 6 ___ / 17CS 101 Spring 2007 Midterm 1 Name: _______________________________ Email ID: ________ 4. [5 points] In about 20 words or less, explain how references and objects differ. 5. [5 points] In about 20 words or less, explain how classes and objects differ. 6. [5 points] In about 20 words or less, explain the difference between a statement and an expression. 7. [5 points] In about 20 words or less, explain what garbage collection is. 8. [5 points] In about 20 words or less, explain the difference between = and ==. Page 3 of 6 ___ / 25CS 101 Spring 2007 Midterm 1 Name: _______________________________ Email ID: ________ 9. [10 points] What are the value AND TYPE of each of the following Java expressions? a. 3 / 4 Value _____________ Type ___________ b. 2.0 / 3 Value _____________ Type ___________ c. 4.0 / 2.0 Value _____________ Type ___________ d. 2 + 3 * 4.0 Value _____________ Type ___________ e. 17 % 7 % 5 Value _____________ Type ___________ f. 17 % (7 % 5) Value _____________ Type ___________ g. !false && true Value _____________ Type ___________ h. !false || false Value _____________ Type ___________ 10. [6 points] List all of the primitive types (hint: there are 8 of them). 11. [4 points] Consider the following code sequence. What are the values of the variables x, y and z after this code runs? int x; x = 7; x’s value: _________ int y; y = 3; int z; y’s value: _________ z = 5; y = z; z = 4; z’s value: _________ Page 4 of 6 ___ / ___ / 20CS 101 Spring 2007 Midterm 1 Name: _______________________________ Email ID: ________ 12. [15 points] Given the following String declaration and initialization: String hexDigits = “0123456789abcdef”; What value does each of the following code segments evaluate to? If they result in a run-time or compile-time error, then state so (you can just write ‘error’; you don’t have to specify which is which). Don’t worry about the lack of semi-colons, however. a. hexDigits.substring (3,4) b. hexDigits.substring (6) c. hexDigits.substring (12) d. hexDigits.indexOf (“c”) e. hexDigits.indexOf (“6”) f. hexDigits.charAt(3) g. hexDigits.length() Page 5 of 6 ___ / ___ / 15CS 101 Spring 2007 Midterm 1 Name: _______________________________ Email ID: ________ 13. [20 points] Consider a Java program that calculates the estimated airspeed velocity of an unladen European swallow. This is roughly 3 times the wingbeat frequency (in wingbeats per second) times the amplitude of the wingbeat (meters per beat – it’s a measure of the vertical distance the wings’ “span” while beating). It is described using the following formula: unladen airspeed velocity = 3.0 * frequency * amplitude in meters You will need to write the relevant parts of this program, in three parts. All the code that is written below is assumed to be in the main() method, so you don’t have to write that (or the ‘public class Foo’ part). You don’t have to worry about any of the “good programming practices” that are normally done in the homeworks. The code you write below, when put in a main() method in a class, and with the appropriate library import lines, should be fully working Java code. a. Write the code that declares a Scanner, and reads in TWO doubles from the keyboard. These doubles represent the variables on the right side of the equation, above. Don’t worry about prompting the user for input. b. Write the code that computes the unladen airspeed velocity. c. Write the code that prints out both the user input and the computed result. Page 6 of 6 ___ /


View Full Document

UVA CS 101 - Midterm 1

Documents in this Course
Classes

Classes

53 pages

Recursion

Recursion

15 pages

Iteration

Iteration

88 pages

PLEDGED

PLEDGED

6 pages

Objects

Objects

33 pages

PLEDGED

PLEDGED

11 pages

CS 101

CS 101

42 pages

Classes

Classes

83 pages

Iteration

Iteration

92 pages

Classes

Classes

186 pages

Classes

Classes

208 pages

Hardware

Hardware

21 pages

Arrays

Arrays

70 pages

Load more
Download Midterm 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Midterm 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Midterm 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?