I. True/False: (2 points each)

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

I. True/False: (2 points each)

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

I. True/False: (2 points each)

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

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010

I. True/False: (2 points each)

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring What is your name?: (4 points for writing it on your answer sheet)

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall What is your name?: (3 points for writing it on your answer sheet)

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2017

Practice Midterm 1 Answer Key

Practice Midterm 1. Problem Points Score TOTAL 50

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 03

CS111: PROGRAMMING LANGUAGE II

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CS 101 Spring 2007 Midterm 2 Name: ID:

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

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

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Intro to Programming in Java Practice Midterm

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

CSCI 201L Written Exam #1 Fall % of course grade

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

Final Exam COMP Fall 2004 Dec 16, 2004

ECE 242 Fall 13 Exam I Profs. Wolf and Tessier

Computer Programming, I. Laboratory Manual. Final Exam Solution

Final Exam. COMP Summer I June 26, points

CS 312 Midterm 1 Spring 2013

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

Arrays. Here is the generic syntax for an array declaration: type[] <var_name>; Here's an example: int[] numbers;

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

CS 113 PRACTICE FINAL

CS111: PROGRAMMING LANGUAGE II

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

COS 126 General Computer Science Fall Written Exam 1

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

CSE 11 Midterm Fall 2012

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

Final Exam Practice. Partial credit will be awarded.

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

CSE 11 Midterm Fall 2008

AP CS Unit 3: Control Structures Notes

Largest Online Community of VU Students

Lecture 14. 'for' loops and Arrays

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

Introduction to Programming (CS112): Sample

COE318 Lecture Notes Week 4 (Sept 26, 2011)

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

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

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

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

Esc101 Mid Semester Exam - II

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

IT Introduction to Programming for I.T. Midterm Exam #1 - Prof. Reed Spring 2008

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean

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

Fall 2002 Page 1 of 9 READ THIS NOW!

Tasks for fmri-setting (Tasks of first and second pilot study at the end)

Problem Grade Total

Object-Oriented Programming and Software Engineering CITS1001 MID-SEMESTER TEST

The Java language has a wide variety of modifiers, including the following:

CSCI 201L Written Exam #1 Fall % of course grade

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

CS 307 Midterm 2 Spring 2008

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

Following is the general form of a typical decision making structure found in most of the programming languages:

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

CS 113 MIDTERM EXAM 2 SPRING 2013

Exam Percentage: / 55 = %

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

COE 212 Engineering Programming. Welcome to Exam II Monday May 13, 2013

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

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

Assignment 1 due Monday at 11:59pm

CMP 326 Midterm Fall 2015

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

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

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.

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

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

CS170 Introduction to Computer Science Midterm 2

CS 177 Week 15 Recitation Slides. Review

Course Outline. Introduction to java

Solutions to Sample JAC444 Midterm Test

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Transcription:

CS 102 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2009 What is your name?: There are three sections: I. True/False..............50 points; (25 questions, 2 points each) II. Multiple Choice........50 points; (10 questions, 5 points each) --------------- 100 points total This test is worth 15% of your final grade. You must put your answers on the bubble form. All code is in Java unless stated otherwise. This test is open book and open notes. For the multiple choice problems, select the best answer for each one and select the appropriate letter on your answer sheet. Be careful - more than one answer may seem to be correct. Some questions are tricky. You have 50 minutes. I. True/False: (2 points each) 1. The turnin command for a project will overwrite any previous files you previously submitted for that project. 2. The following is a valid declaration in Java: boolean if = true; 3. The following statements compile and run in Java: String one = "two"; if( one == "two") System.out.println("Are same"); 4. When writing a class that is to be used by others, you should at a minimum implement the get and set methods, default constructor, fully qualified constructor, copy constructor, equals method, and the tostring method. 5. Two methods in Java can have the same name and same number of parameters. 6. Two methods in Java can have the same name, type and number of parameters, as long as the method return types are different. 7. In order for the code shown below to compile and run properly, a copy constructor for the Date class must exist. Date d1 = new Date(2,14,2000); Date d2 = new Date( d1); 8. To chain constructors you must use this. 9. If a parameter has the same name as a class (instance) variable name, using that variable will by default refer to the instance variable, not to the parameter. 10. If a parameter has the same name as a class (instance) variable name, we can explicitly refer to the instance variable by using this. CS 102 - Intro. to Programming, Midterm Exam #2, page 1 of 7

11. Given the Date5 class discussed in our lectures, the follow code will give the output: NOT equal Date5 d1 = new Date5( 1,1,2010); Date5 d2 = new Date5( 1,1,2010); if( d1==d2) System.out.println("Are equal"); else System.out.println("NOT equal"); 12. Assuming the Date5 class as developed in our lectures, the tostring method gets called automatically in the following code: Date5 d3 = new Date5(); System.out.println("Date is: " + d3); 13. Given the Date5 class discussed in our lectures, the follow code will give the output: 1/31/2009 Date5 d1 = new Date5( 12,31,2009); Date5 d2 = d1; d1.setmonth(1); System.out.println( d2); 14. A static variable s value cannot be changed. 15. A static method such as main( ) can not access non-static instance variables. 16. A non-static method can access static instance variables. 17. Private instance variables can only be accessed through code in the class where they are declared. 18. The following Java code would compile and run: int[] values = 1,2,3,4,5; int x = values[ values[4] ]; System.out.println( x); 19. Consider the Square class and Board class as used in our programming assignments. Assume the following code would be in the Board class. Square s1 = new Square(30,30,60,"red",true,""); Square s2 = s1; s2.setcolor("green"); When run this code will display two different colored Squares on the Canvas. 20. Every program can be written with all the looping code implemented using only for loops. 21. Every program can be written with all the looping code implemented using only while loops. 22. Every program can be written with all the looping code implemented using only do loops. 23. Every program can be written with all the looping code implemented using recursion. CS 102 - Intro. to Programming, Midterm Exam #2, page 2 of 7

24. The length() method is used for both strings and arrays. You must be sure to include the parenthesis in both cases. 25. Assume the code shown below, where method swapvalues2 is called. Output of this segment of code is: Values are: abcd char[] letters = a, c, b, d ; swapvalues2( letters, 1, 2); System.out.print("Values are: "); System.out.println( letters); // for the line above, think of class Monday... public void swapvalues2(char[] a, int num1, int num2) char temp = a[num1]; a[num1] = a[num2]; a[num2] = temp; II. Multiple Choice (5 pts. each) 26. Consider the method given below. It can best be described as a method that: public boolean method26( int number) if( number==1) return false; if( number==2) return true; for (int i=2; i <= number/2; i++) if ( number%i == 0) return false; return true; a) checks to see if a number is even b) checks to see if a number is odd c) checks to see if a number is prime d) does not compile CS 102 - Intro. to Programming, Midterm Exam #2, page 3 of 7

27. Consider the method given below. What would be the output if this were called using the statement: System.out.println( method27( 1357)); int method27( int number) int x = number; int y = 0; while ( x > 0) y = y * 10 + x%10; x = x / 10; return y; a) 1 b) 7 c) 35 d) 7531 28. Consider the code shown at right below, that uses the Square class demonstrated during class. What does the output of this code look like? a) A square that itself moves in a clockwise inward shrinking spiral. b) A square that itself moves in a clockwise constant size circle. c) A square that itself moves in a counter-clockwise constant size circle. d) A square that itself moves in a counter-clockwise outward growing spiral.. public class Picture public static void main(string[] args) Square firstsquare = new Square(); firstsquare.makevisible(); for (int i=31;i>0;i--) firstsquare..slowmovevertical(i*2); firstsquare..slowmovehorizontal(i*2); firstsquare..slowmovevertical((-i)*2); firstsquare..slowmovehorizontal((-i)*2); //end for( int i... //end main... //end class Picture CS 102 - Intro. to Programming, Midterm Exam #2, page 4 of 7

29. What is the output of the program segment shown at right below? (Note that Math.abs in the code below gives the absolute value of the argument.) a) * *** ** **** b) **** ** *** * c) * *** ** **** ** *** * d) * *** ** **** ** *** * int LIMIT = 11; for( int i=1; i<=limit; i++) for( int k=0; k<=math.abs(i-6); k++) System.out.print(' '); if( i <= (LIMIT+1)/2) for( int j=1; j<i*2; j++) System.out.print('*'); else for( int j=1; j<((limit+1)-i)*2; j++) System.out.print('*'); System.out.println(); //end for( int i... 30. Consider method first shown at right. For positive numbers, how would you best describe its return value? a) x + y b) x * x c) x * y d) x y 31. Consider method second shown at right. For positive numbers, how would you best describe its return value? a) x + y b) x * x c) x * y d) x y int first( int x, int y) if( y == 0) return x; else return first(x, y-1) + 1; public int second(int x, int y) int z=0; for (int i=0; i<y; i++) z = first( z, x); return z; CS 102 - Intro. to Programming, Midterm Exam #2, page 5 of 7

32. Consider the class given below, along with the driver class for it. class ClassB private int value; public ClassB() value = 1; public void setvalue(int value) value = value + 2; //end ClassB class ClassBDriver public void doit() int number = 2; ClassB instance1 = new ClassB(); instance1.setvalue( number); number = instance1.value; System.out.println("value is: "+number); //end ClassBDriver When running method doit() in the ClassBDriver class, what is the result? output will be: a) Output will be: value is: 1 b) Output will be: value is: 2 c) Output will be: value is: 4 d) Doesn t compile 33. Assume that you create class Employee that includes an instance of class Date to store the startdate for each employee. Assume that you have written some test code in class EmployeeDriver shown below, where you change the startdate for e1. To your surprise when you run this code the startdate for e2 has changed as well. What is the most likely explanation for this? class EmployeeDriver public static void main(string[] args) Employee e1 = new Employee(); Employee e2 = new Employee( e1); e1.changedate( 9, 30, 1923); System.out.println(e1); System.out.println(e2); a) The Date class fields are declared as static b) The Employee copy constructor does not create a new Date c) The Date class copy constructor does not chain to the fully qualified constructor d) The new value happens to be the same as the default value CS 102 - Intro. to Programming, Midterm Exam #2, page 6 of 7

34. What is the output of the code given below when method usearray() is called? public void usearray() char[] thearray= 'E','n','t','r','o','p','y'; processarray( thearray); for(int i=0; i<thearray.length; i++) System.out.print( thearray[i]); public void processarray(char[] w) int x = w.length; char c; for (int i=0; i<x/2; i++) c = w[i]; w[i] = w[x-i-1]; w[x-i-1] = c; a) The contents of the original array in reverse order b) The contents of the original array in the original order c) The contents of the original array with half of the characters reversed d) The original array with characters rearranged so they are neither in the original nor reversed orde 35. What is the output of the code below when bubblesort is called using the following: int[] values = 1,5,7,8,9,13,15; bubblesort( values); void bubblesort( int[] thearray) int counter = 0; int pass, current; for ( pass=1; pass < thearray.length; pass++) for ( current=0; current < thearray.length-pass; current++) if ( thearray[ current] < thearray[ current+1]) swap( thearray, current, current+1); counter++; //end for ( current //end for (pass System.out.println( counter); //end method bubblesort public void swap( int[] thearray, int i, int j) int temp = thearray[i]; thearray[i] = thearray[j]; thearray[j] = temp; a) 7 b) 19 c) 20 d) 21 CS 102 - Intro. to Programming, Midterm Exam #2, page 7 of 7