CS 101 Spring 2007 Midterm 2 Name: ID:

Similar documents
CS 101 Fall 2006 Midterm 3 Name: ID:

CS 101 Fall 2006 Midterm 1 Name: ID:

CS 101 Fall 2005 Midterm 2 Name: ID:

This exam is open book. Each question is worth 3 points.

CS 101 Exam 2 Spring Id Name

CS 101 Spring 2006 Final Exam Name: ID:

Controls Structure for Repetition

Question: Total Points: Score:

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

COS 126 General Computer Science Fall Written Exam 1

CS 101 Exam 1 Spring 200 Id Name

Loops. CSE 114, Computer Science 1 Stony Brook University

Page 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge:

Advanced if/else & Cumulative Sum

CS 177 Week 15 Recitation Slides. Review

COS 126 Midterm 1 Written Exam Fall 2011

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

Give one example where you might wish to use a three dimensional array

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

H212 Introduction to Software Systems Honors

COS 126 General Computer Science Spring Written Exam 1

Arrays. Eng. Mohammed Abdualal

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

CS170 (005): Introduction to Computer Science Exam 2

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

COS 126 Midterm 1 Written Exam Fall 2012

AP COMPUTER SCIENCE A

CompSci 125 Lecture 11

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

Bjarne Stroustrup. creator of C++

CS212 Midterm. 1. Read the following code fragments and answer the questions.

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

COS 126 General Computer Science Fall Programming Exam 2

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

COS 126 General Computer Science Fall Exam 1

Lecture 5: Methods CS2301

(the bubble footer is automatically inserted into this space)

1 Short Answer (5 Points Each)

CS170 Introduction to Computer Science Midterm 2

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

1 Short Answer (10 Points Each)

COS 126 Midterm 1 Written Exam, Fall 2009

COS 126 Midterm 1 Written Exam Spring 2015

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

Loops and Expression Types

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

CS : Introduction to Computer Programming Final Exam December 9, Please wait to open this exam booklet until you are told to do so.

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

I. True/False: (2 points each)

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

McGill University School of Computer Science COMP-202A Introduction to Computing 1

CS 201, Fall 2016 Sep 28th Exam 1

Practice Midterm 1. Problem Points Score TOTAL 50

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

AP Computer Science A Summer Assignment 2017

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

COS 126 General Computer Science Fall Exam 1

Example: Monte Carlo Simulation 1

AP Computer Science Unit 1. Programs

CS 231 Data Structures and Algorithms, Fall 2016

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

CS 177 Recitation. Week 8 Methods

Iteration: Intro. Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times. 2. Posttest Condition follows body Iterates 1+ times

Question: Total Points: Score:

Programming Exercise 7: Static Methods

CS171:Introduction to Computer Science II

New York University Introduction to Computer Science Midterm2 Sample Problems 2013 Andrew I. Case. Instructions:

Handout 4 Conditionals. Boolean Expressions.

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

(the bubble footer is automatically inserted in this space)

CSE 8A Lecture 21. SMarx extra final exam office hours Fri 3/15 11:15am-1pm EBU-3B #2206

Programming with Java

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

Final Exam. COMP Summer I June 26, points

Introduction to Programming Written Examination

Object Oriented Programming. Java-Lecture 1

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Array. Lecture 12. Based on Slides of Dr. Norazah Yusof

I have neither given nor received any assistance in the taking of this exam.

Nested Loops ***** ***** ***** ***** ***** We know we can print out one line of this square as follows: System.out.

1 Short Answer (10 Points Each)

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM

Final Exam COMP Fall 2004 Dec 16, 2004

CSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:

Instructor: Yu Wang 11/16/2012

CS : Introduction to Computer Programming Final Exam December 9, Please wait to open this exam booklet until you are told to do so.

CS111: PROGRAMMING LANGUAGE II

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

The for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming

Transcription:

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 / 24 Page 3 / 9 Page 4 / 16 Page 5 / 21 Page 6 / 17 Page 7 / 10 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-3 (lab 9:30 10:45 a.m. Thu) CS 101-4 (lab 11:00 12:15 p.m. Thu) CS 101-5 (lab 12:30 1:45 p.m. Thu) CS 101-6 (lab 2:00 3:15 p.m. Thu) CS 101-7 (lab 3:30 4:45 p.m. Thu) CS 101-8 (lab 5:00 6:15 p.m. Thu) CS 101-9 (lab 6:30 7:45 p.m. Thu) Page 1 of 7

2. [4 points] In about 20 words or less, explain how classes and objects differ. 3. [6 points] In about 20 words or less, explain what the halting problem is 4. [6 points] In about 20 words or less, explain why the halting problem is so important. 5. [4 points] In about 20 words or less, explain why we need to use the.equals() method when comparing String objects. 6. [4 points] In about 20 words or less, explain the difference between a while loop and a do-while loop / 24 Page 2 of 7

7. [9 points] Answer the following questions based on the following code: public static void main(string [] args) { Scanner stdin = new Scanner(System.in); System.out.println ( Please enter the number + of textbooks you read. ); int books = stdin.nextint(); int browniepoints = 10; if (books < 1) { browniepoints -= 1; if (books < 3) { browniepoints -= 3; if (books < 5) { browniepoints -= 5; browniepoints += 10; System.out.println( Based on your input you have: + browniepoints + brownie points. ); a. What is printed if the user enters: 3? Based on your input you have: brownie points. b. What is printed if the user enters: 0? Based on your input you have: brownie points. c. What is printed if the user enters: 7? Based on your input you have: brownie points. / 9 Page 3 of 7

8. [6 points] Given the following code, write an equivalent nested if statement. Assume that amount1, amount2, and max are all ints which are previously declared and initialized. if( amount1 > 5 && amount2 < 10) { max = (amount1 > amount2)? amount1 : amount2; System.out.println ( The maximum is: + max); 9. [5 points] Write an statement using the?: notation that assigns 30 to the variable y if the variable y is greater than 10 (assume all variables are ints and have been properly declared and initialized). 10. [5 points] The following code to sum even numbers less than 100 has a bug. Find and explain the bug in about 20 words or less. int sum = 0; for(int number = 0; number < 100; number += 2) { sum += number; number++; / 16 Page 4 of 7

11. [7 points] Write a while loop which displays the following numbers (they can be on separate lines, and don t need the commas): 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 12. [7 points] Convert the following while loop to a for loop: i = 100; while (i > 0) { System.out.println( i is : + i); i--; [7 points] Write a for loop that will go through a Vector object v (which has been properly declared and initialized already), and print out each String that is in the object. Remember that Vectors have a.size() method that will return the number of elements in the Vector. / 21 Page 5 of 7

13. [8 points] Given the following method signatures, list the return type. a. public static void main(string [] args) { return type: b. public double cos(int angle) { return type: c. public Circle() { return type: d. public static int max(int x, int y) { return type: e. public String tostring() { return type: 14. [9 points] Consider the following code: if ( i j ) { if ( j && k ) { System.out.println("A ); else if (!k i ) { System.out.println( B ); System.out.println( C ); else if (!j && k ) { System.out.println( D ); if ( i k ) { System.out.println( E ); System.out.println( F ); a. What is printed if i is true, j is false, and k is true? b. What is printed if i, j, and k are all false? c. What values of i, j, and k are needed to print D? / 17 Page 6 of 7

15. [10 points] When an object is falling due to gravity, the distance (in meters) it falls is calculated as one 1 2 half the gravity multiplied by the square of the falling time (in seconds) in other words, d = g * t, 2 where d is the distance fallen, g is gravity, and t is the time taken. You may assume that gravity is fixed at 9.8 m/s 2. Write a method called distancefallen that accepts the object s falling time as a double and returns the distance fallen as a double. / 10 Page 7 of 7