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

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

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

CS 2334: Programming Structures and Abstractions Final Exam December 13, Please wait to open this exam booklet until you are told to do so.

CS 2334: Programming Structures and Abstractions Exam 2 November 4, Please wait to open this exam booklet until you are told to do so.

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

Object Oriented Programming 2015/16. Final Exam June 17, 2016

Final Exam COMP Fall 2004 Dec 16, 2004

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.

CS 101 Spring 2007 Midterm 2 Name: ID:

I. True/False: (2 points each)

CS 132 Midterm Exam Fall 2004

Final Exam. COMP Summer I June 26, points

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

CS 113 PRACTICE FINAL

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Last Name: Circle One: OCW Non-OCW

CS 1322 Test 2 - Version 1 Tuesday June 24 th

Introduction to Computing II (ITI 1121) Final Examination

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

Ryerson University Department of Electrical & Computer Engineering COE618 Midterm Examination February 26, 2013

CS170 Introduction to Computer Science Midterm 2

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

Introduction to Computer Science Midterm 3 Fall, Points

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

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

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

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill

JAVA MOCK TEST JAVA MOCK TEST II

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2017 Instructors: Bill & Bill

CS 101 Fall 2005 Midterm 2 Name: ID:

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

I. True/False: (2 points each)

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

ECE Fall 2015, First Exam

CSCE 206: Structured Programming in C++

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

CS 101 Spring 2006 Final Exam Name: ID:

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

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

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

P2: Advanced Java & Exam Preparation

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.

CIS 110 Introduction to Computer Programming Summer 2017 Final. Recitation # (e.g., 201):

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

Informatik II (D-ITET) Tutorial 6

Name Section Number. Sections 1-3 *** TURN OFF ALL ELECTRONIC DEVICES*** Bob Wilson

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

COS 126 Midterm 1 Written Exam, Fall 2009

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

Selected Java Topics

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

CS 132 Midterm Exam Spring 2004

CIS 110 Introduction to Computer Programming Spring 2016 Final Exam

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Two hours QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

Prelim One Solution. CS211 Fall Name. NetID

CS159. Nathan Sprague

CS Week 14. Jim Williams, PhD

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

PASS4TEST IT 인증시험덤프전문사이트

Final Exam Practice Questions

Unit 4: Classes and Objects Notes

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Midterm Exam 2 CS 455, Spring 2013

Final Exam Practice. Partial credit will be awarded.

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

COS 126 General Computer Science Spring Written Exam 1

COMP 401 Spring 2013 Midterm 2

CS 101 Exam 2 Spring Id Name

Exam Duration: 2hrs and 30min Software Design

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5,

Object Oriented Programming 2015/16. Final Exam June 28, 2016

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015

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

Exam Percentage: / 55 = %

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Note that if both p1 and p2 are null, equals returns true.

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11

Question: Total Points: Score:

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

1 Method Signatures and Overloading (3 minutes, 2 points)

AP CS Unit 8: Inheritance Exercises

COP 3330 Final Exam Review

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

RAIK 183H Examination 2 Solution. November 10, 2014

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

CIS Introduction to Computer Programming Spring Exam 1

Introduction to Computer Science II (CSI 1101)

CSE 331 Summer 2017 Final Exam. The exam is closed book and closed electronics. One page of notes is allowed.

CS 1331 Fall 2016 Exam 2

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

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

Practice Midterm 1. Problem Points Score TOTAL 50

CS159. Nathan Sprague

Object Oriented Programming 2014/15. Final Exam July 3, 2015

Object- Oriented Analysis, Design and Programming

Transcription:

General instructions: CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016 Please wait to open this exam booklet until you are told to do so. This examination booklet has 13 pages. You also have been issued a bubble sheet. Fill in the identifying information below (signature, name, ID and date) Also, write your name and ID number on your bubble sheet, and fill in the bubbles for your ID. You may have up to five pages of your own notes. No electronic devices or books may be used. The exam is worth a total of 137 points. Your grade counts for 10% of your final grade. You have 1.25 hours to complete the exam. Be a smart test taker: if you get stuck on one problem go on to the next. Use your bubble sheet to answer all multiple-choice questions. Make sure that the question number and the bubble row number match. Other than this page, you may tear any other page out of this booklet that does not contain numbered answers. If you cannot effectively erase erroneous answers from the bubble sheet, please clearly cross them out. On my honor, I affirm that I have neither given nor received inappropriate aid in the completion of this exam. Signature: ID Number: Name: Date: C A B C C A A B A C B Question Points Score Types and Objects 32 Inheritance and Polymorphism 35 UML and Object Oriented Design 14 Abstract Classes and Interfaces 24 Exceptions and Error Handling 28 Miscellaneous 4 Total: 137

Part I. Types and Objects 1. (4 points) What is printed by this block of code? 1 String s1 = XHT ; 2 String s2 = xht ; 3 s2. touppercase () ; 4 if (s1.equals(s2)) 5 6 System.out.println ( Yes: + s1) ; 7 8 else 9 10 System.out.println ( No: + s2) ; 11 A. No:xHt B. No:XHT C. Yes:xHt D. Yes:XHT E. Compilation error or answer not shown 2. (4 points) What is printed by this block of code? 1 int a = 4; 2 double c = 11; 3 int b = c+7; 4 c += b; 5 System.out.println (c) ; A. 15.0 B. 18.0 C. 22.0 D. 29.0 E. Compilation error or answer not shown 3. (4 points) What is printed by this block of code? 1 int i1 = 7; 2 int i2 = 5; 3 System.out.println (i1/i2) ; A. 0 B. 1 C. 1.4 D. 12 E. Compilation error or answer not shown 4. (4 points) What is printed by this block of code? 1 String a = OOM ; 2 Integer b = 5; 3 Integer c = new Integer (19) ; 4 System.out.println (c + b + a) ; A. 14OOM B. 19-5M C. 19-5OOM D. -519OOM E. Compilation error or answer not shown CS 2334-010 Exam 1 Page 2 of 13

5. (4 points) What is printed by this block of code? 1 int a = 3; 2 int b = 7; 3 String c = 7117 ; 4 System.out.println (c + (a + b)) ; A. 7127 B. 711710 C. 711737 D. 711773 E. Compilation error or answer not shown 6. (4 points) What is printed by this block of code? 1 int a = 32; 2 String b = 4EB ; 3 int c = 8; 4 System.out.println (a + c + b) ; A. 324EB8 B. 3284EB C. 404EB D. 84EB32 E. Compilation error or answer not shown 7. (4 points) What is printed by this block of code? 1 int a = 17; 2 String b = YYO ; 3 int c = 22; 4 System.out.println (b + c + a) ; A. YY39 B. YYO39 C. YYO1722 D. YYO2217 E. Compilation error or answer not shown 8. (4 points) What is printed by this block of code? 1 int i1 = 42; 2 String s = 8 ; 3 System.out.println (i1 + s) ; A. 6 B. 50 C. 428 D. 842 E. Compilation error or answer not shown CS 2334-010 Exam 1 Page 3 of 13

Part II. Inheritance and Polymorphism Consider the following class definitions: public class A private int val ; public A( int val) this.val = val ; public int getval () return val ; public String tostring () return A: + this.getval () ; public class B extends A private String name ; public B( int val, String name) super(val) ; this.name = name ; public String getname () return name ; public class C extends B private int val ; public C( int val, String name) super(val 2, name) ; this.val = val ; public C(String name, int val) super(val, name. tolowercase () ) ; this.val = 1; public int getval () return val ; public int getsuperval () return super.getval () ; public String tostring () return C: + this.getname () + : + super. tostring () ; CS 2334-010 Exam 1 Page 4 of 13

9. (7 points) What is printed by this block of code? C e = new C( Ann, 3) ; System.out.println (e.getval () + e.getsuperval () ) ; A. -1 B. 1 C. 2 D. 3 10. (7 points) What is printed by this block of code? C d = new C( Henry, 19) ; System.out.println (d) ; A. C:henry:A:19 B. C:Henry:A:19 C. C:henry:A:-1 D. C:Henry:A:-1 11. (7 points) What is printed by this block of code? B b = new B(79, Bob ) ; System.out.println (b) ; A. A:79 B. B:79 C. Bob:79 D. B:Bob:79 12. (7 points) What is printed by this block of code? A a = new A(42) ; System.out.println (a) ; A. A: B. A:42 C. A:84 D. A:A:42 13. (7 points) What is printed by this block of code? C c = new C(83, Joe ) ; System.out.println (c) ; A. C:Joe:A:-1 B. C:Joe:A:-2 C. C:Joe:A:83 D. C:Joe:166 CS 2334-010 Exam 1 Page 5 of 13

Part III. UML and Object Oriented Design 14. (6 points) Which UML diagram corresponds to the following code? public class Person private String Name ; public class Coach extends Person private ArrayList<Player> players ; public class Player extends Person private Coach coach ; public class Team private Coach coach ; private ArrayList<Player> players ; A. B. C. D. CS 2334-010 Exam 1 Page 6 of 13

15. (4 points) Carefully examine the following UML models and select the one that corresponds to the following code. public class MyClass private double val ; protected char c; public MyClass (char c, double val) this.val = val ; this.c = c; private void print () System.out.println (c) ; public double doublevalue () return val 2; A. B. C. D. CS 2334-010 Exam 1 Page 7 of 13

16. (4 points) Which set of class definitions corresponds to the following UML diagram? A. public abstract class One... public abstract class Two extends One... public class Three extends Two... public class Four extends Two... B. public interface One... public interface Two implements One... public class Three extends Two... public class Four implements One... C. public class One... public class Two extends One... public class Three extends Two... public class Four extends One... D. public abstract class One... public abstract class Two extends One... public class Three extends Two... public class Four extends One... CS 2334-010 Exam 1 Page 8 of 13

Part IV. Abstract Classes and Interfaces 17. (4 points) Which line (if any) will cause the program not to compile? 1 public interface MyInterface 2 3 public int value ; 4 5 public abstract double setdouble (double v) 6 7 value = v; 8 9 public abstract String tostring () ; 10 A. 3 B. 5 C. 7 D. Multiple lines 18. (4 points) Which line (if any) will cause the program not to compile? 1 public interface MyList 2 3 public abstract void add(integer i) ; 4 public abstract Integer get( int j) ; 5 public abstract void insert(integer i, int j) ; 6 A. 1 B. 3 C. 4 D. 5 19. (4 points) Which line (if any) will cause the program not to compile? 1 public abstract class Worker 2 3 private double workrate ; 4 5 public Worker(double workrate ) 6 7 this. workrate = workrate ; 8 9 10 public abstract boolean candowork () ; 11 12 public double dowork () 13 14 if ( this.candowork () ) 15 16 return this.workrate ; 17 18 else 19 20 return 0; 21 22 23 A. 7 B. 10 C. 14 D. 16 CS 2334-010 Exam 1 Page 9 of 13

20. (4 points) Any class that extends an abstract class must provide implementations for all of the abstract methods. A. True B. False C. Answer not shown Consider the following class definition for the next two questions: 1 public class Course implements Comparator<Course> 2 3 private String name ; 4 private int grade ; 5 6 public Course( int name, String grade) 7 8 this.name = name ; 9 this.grade = grade ; 10 11 12 / 13 Sort first by grade and then by the 14 natural order of the names. 15 @return 1 if c1 comes after c2 ; 1 if c1 comes before c2 ; 16 and 0 if they are equal 17 / 18 public int compare (Course c1, Course c2) 19 20 if (c1.grade < c2.grade) 21 22 return 1; 23 24 else if (c1.grade > c2.grade) 25 26 return 1; 27 28 else 29 30 return c2.name.compareto (c1.name) ; 31 32 33 21. (4 points) Which one line can be changed to fix a bug in the class definition or the Course constructor? A. 1 B. 6 C. 8 D. 9 22. (4 points) Which one line can be changed to fix a bug in the compare() method? A. 18 B. 20 C. 24 D. 30 CS 2334-010 Exam 1 Page 10 of 13

Part V. Exceptions and Error Handling Consider the following program: public class ExceptionsOnExam public static int dosubjob ( int value) if (value <= 5) throw new IllegalArgumentException( Error 1 ) ; else if (value > 8) throw new IllegalStateException( Error 2 ) ; else return 42; public static int dojob( int arg) int value = 1; if (arg <= 10 && arg >= 2) try return dosubjob (arg + value) ; catch( IllegalArgumentException e) return value ; else return dosubjob (2 value) ; public static void main(string [] args) int value =????; try int ret = dojob(value) ; System.out.println (ret) ; catch (Exception e) System.out.println (e.getmessage () ) ; Note that both IllegalArgumentException and IllegalStateException are RuntimeExceptions. CS 2334-010 Exam 1 Page 11 of 13

23. (7 points) Assume that value = 10 in main(), what is printed by the program? A. Error 1 B. Error 2 C. -1 D. 42 24. (7 points) Assume that value = 6 in main(), what is printed by the program? A. Error 1 B. Error 2 C. -1 D. 42 25. (7 points) Assume that value = 7 in main(), what is printed by the program? A. Error 1 B. Error 2 C. -1 D. 42 26. (7 points) Assume that value = 1 in main(), what is printed by the program? A. Error 1 B. Error 2 C. -1 D. 42 CS 2334-010 Exam 1 Page 12 of 13

Part VI. Miscellaneous Consider the following program: 1 public class MyClass 2 3 private double val ; 4 protected char c; 5 6 public MyClass(char c, double val) 7 this.val = val ; 8 this.c = c; 9 10 11 private void print () 12 System.out.println(c) ; 13 14 15 public double doublevalue () 16 return val 2; 17 18 19 public static void main(string [] args) 20 21 MyClass m = new MyClass ( ³a ³, 7.2) ; 22 int a = 4; 23 24 System.out.println(m + a) ; 25 26 27. (2 points) In which part of memory is the variable declared on line 4 stored? A. Heap B. Stack C. Answer not shown 28. (2 points) In which part of memory is the variable declared on line 22 stored? A. Heap B. Stack C. Answer not shown CS 2334-010 Exam 1 Page 13 of 13