DOC PREVIEW
UVA CS 101 - Midterm 1

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 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 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 101 Fall 2005 Midterm 1 Name: ____________________________ Email ID: ________ 1 This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final question is worth substantially more than any other question), so be sure to look over all the questions and plan your time accordingly. Please sign the honor pledge here: __________________________________________________________________________________ __________________________________________________________________________________ __________________________________________________________________________________ Page 1 ____ / 4 Page 2 ____ / 25 Page 3 ____ / 12 Page 4 ____ / 13 Page 5 ____ / 16 Page 6 ____ / 10 Page 7 ____ / 20 Total ____ / 100 Note: When an integer type is required use int, when a floating-point type is required use double. 1. (2 points) What section are you in? ____ CS 101-E ____ CS 101-2 (lab 7-8:30 PM Thu) ____ CS 101-3 (lab 12-1:30 PM Fri) ____ CS 101-4 (lab 2-3:30 PM Fri) 2. (2 points) What is your overall impression of the class so far? Check only one in each column. ___ Too slow ___ Too easy ___ Too fast ___ Too hard ___ Just right ___ Just right ___ / 4CS 101 Fall 2005 Midterm 1 Name: ____________________________ Email ID: ________ 2 3. (3 points) What is the value of the following expression? (0.75 * 4.0) 4. (3 points) What is the value of the following expression? ((3/4) * 4) 5. (3 points) What is the value of the following expression? (25 % 5 - 2) 6. (3 points) What is the value of the following expression? (12 / 1+5) 7. (3 points) What is the value of the following expression? (12 / 5 + 1.0) 8. (3 points) What is the value of the following expression? (12 / 5.0 + 1) 9. (4 points) When a Java application program is run, execution always begins by calling a certain method. Show exactly how you declare this method. 10. (3 points) Give a Java statement to define and initialize a floating-point constant to represent the number of radians per degree (which is /180.0). You may approximate this value in your code as 0.0175. ___ / 25CS 101 Fall 2005 Midterm 1 Name: ____________________________ Email ID: ________ 3 11. (3 points) Give a Java statement to define and initialize an integer variable to represent how many pigeons fit in a pigeonhole (you pick the value). 12. (3 points) Does the following code snippet compile without error? If not, explain the error that prevents the code from compiling. If the code does successfully compile, give the value of all variables after the code snippet executes: int i = 3; int n = 4; i = n; n = i; 13. (3 points) Does the following code snippet compile without error? If not, explain the error that prevents the code from compiling. If the code does successfully compile, give the value of all variables after the code snippet executes: int i = 3; int n = 4; i = 2 * i * n; 14. (3 points) Does the following code snippet compile without error? If not, explain the error that prevents the code from compiling. If the code does successfully compile, give the value of all variables after the code snippet executes: double pi = 3.14; int n = 2; n = n * pi; ___ / 12CS 101 Fall 2005 Midterm 1 Name: ____________________________ Email ID: ________ 4 15. (3 points) Does the following Java code snippet compile without error? If not, explain the error that prevents the code from compiling. If the code does successfully compile, give the value of all variables after the code snippet executes: double pi = 3.14; double radius; double circumference = 2.0 * pi * radius; 16. (3 points) Write a single statement that declares and initializes a Scanner object that will read user input from the keyboard. 17. (4 points) Write a code snippet that prompts the user to enter the number of blackbirds per pie, and uses the Scanner object declared above to read it into an integer variable. 18. (3 points) Write a Java comment stating that most pies contain 24 blackbirds. ___ / 13CS 101 Fall 2005 Midterm 1 Name: ____________________________ Email ID: ________ 5 19. (6 points) Explain BRIEFLY (30 words or less total) what the difference is between: String s; and String t = null; and String u = ""; 20. (10 points) Consider the following code segment: String quote = "the quick brown fox"; System.out.println("length = " + quote.length()); System.out.println("indexOf('q') = " + quote.indexOf('q')); System.out.println("indexOf('z') = " + quote.indexOf('z')); System.out.println("substring(0,2) = " +quote.substring(0,2)); System.out.println("substring(4) = " + quote.substring(4)); System.out.println("charAt(8) = " + quote.charAt(8)); What is the output? ___ / 16CS 101 Fall 2005 Midterm 1 Name: ____________________________ Email ID: ________ 6 21. (10 points) Using the memory depiction techniques that we have used in the book and in lecture, draw what memory looks like after the following Java code completes. String s = "foo"; String t = s; Rectangle r = new Rectangle (1,2,3,4); Rectangle s = new Rectangle (1,2,3,4); int x = 5; int y; ___ / 10CS 101 Fall 2005 Midterm 1 Name: ____________________________ Email ID: ________ 7 22. (20 points) Write an entire, complete Java program that prompts the user to input their first, last, and middle names (separately and in that order), then prints out their name in the following form: "Luebke, David P." Note that you should abbreviate their middle name (including the period). This program will have to be in a class named NameGames. For brevity you may omit the "good programming practices": comments, printing a legend, echoing input, etc. You may use the back of this page if you need more space. Your program should go through the following steps: 1) Create a Scanner object 2) Prompt for and obtain the three names 3) Find the middle initial from the middle name (hint: you can use substring()) 4) Create the final form of the name (i.e. "Luebke, David P.") 5) Print the output ___ /


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?