Student s Number: This exam consists of 30 multiple choice questions. Mark your answer to each question in the space provided on this page.

Similar documents
Question: Total Points: Score:

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

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

PROGRAMMING FUNDAMENTALS

Loops. CSE 114, Computer Science 1 Stony Brook University

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

Computer Programming, I. Laboratory Manual. Final Exam Solution

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

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

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

Getting started with Java

University of Palestine. Mid Exam Total Grade: 100

Selected Questions from by Nageshwara Rao

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

Java Simple Data Types

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

Lara Technologies Special-Six Test

Problem Grade Total

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

Computational Expression

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

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

CS 231 Data Structures and Algorithms, Fall 2016

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

COE 212 Engineering Programming. Welcome to Exam II Tuesday November 28, 2018

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

Bjarne Stroustrup. creator of C++

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID:

Set<Integer> s = new TreeSet<Integer>(); s.add( 7 ); s.add( 7 ); System.out.println( s.size() );

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Key Java Simple Data Types

Java Simple Data Types

d. If a is false and b is false then the output is "ELSE" Answer?

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

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

More on methods and variables. Fundamentals of Computer Science Keith Vertanen

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

CSEN 202: Introduction to Computer Programming Spring term Final Exam

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

CIS October 19, 2017

Question: Total Points: Score:

Section 004 Spring CS 170 Exam 1. Name (print): Instructions:

Some Practice Midterm Problems

I. True/False: (2 points each)

1.Which four options describe the correct default values for array elements of the types indicated?

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

Csci 102: Sample Exam

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

Introduction to Java

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Final Exam. Kenneth J. Goldman December 18, Name: Student ID Number: Signature:

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

CS251L REVIEW Derek Trumbo UNM

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Question: Total Points: Score:

Selenium Class 9 - Java Operators

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

CS171:Introduction to Computer Science II

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

CSC Java Programming, Fall Java Data Types and Control Constructs

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

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

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

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

CSE 1223: Exam II Autumn 2016

Question: Total Points: Score:

University of Maryland College Park Dept of Computer Science

Instructions. Grading Box 2. /10 4. /10 1. /10 3. /10 5. /10. Total /50

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

6 COMPUTER PROGRAMMING

INTRODUCTION TO SOFTWARE SYSTEMS (COMP1110/COMP1140/COMP1510/COMP6710)

( &% class MyClass { }

Introduction to Functional Programming in Java 8

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

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

Conditional Execution

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

Java Basic Programming Constructs

CSC 1214: Object-Oriented Programming

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

Operators Questions

Array. Array Declaration:

University of Massachusetts Amherst, Electrical and Computer Engineering

Chapter 3. Selections

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

CIS October 16, 2018

Vendor: Oracle. Exam Code: 1Z Exam Name: Java SE 8 Programmer. Version: Demo

Object- Oriented Analysis, Design and Programming

The code XXX1XXX, XXX2XXX, XXX3XXX represents pieces of code that are missing from the method that are needed to make it work properly.

Final Exam Practice. Partial credit will be awarded.

CS 177 Spring 2010 Exam I

COE 211/COE 212 Computer/Engineering Programming. Welcome to Exam II Thursday December 20, 2012

Transcription:

CSE 1020.03 page 1 of 12 Student s Name: Student s Number: Student s CSE ID: Student s Instructor This exam consists of 30 multiple choice questions. Mark your answer to each question in the space provided on this page. Question Answer Question Answer 1 16 2 17 3 18 4 19 5 20 6 21 7 22 8 23 9 24 10 25 11 26 12 27 13 28 14 29 15 30 Note: Only answers in the boxes above will be graded. Make sure your name is on the page. Do not turn this page over until told to do so.

CSE 1020.03 page 2 of 12 Consider the following Java program public class Silly { public static void main(string[] args) { int x = 3; Integer yy = new Integer(123); if(x < 10) System.out.println("Yes!"); 1. In Silly a complete list of the Separators is (a). ; (b) { ( ) [ ] ;. (c), ; { [ ] ( ) < = (d) { [ ] ( ), ; < = 123 3 10 (e) None of the above 2. In Silly a complete list of the Operators is (a) = (b) < (c) = < (d). = < (e) None of the above 3. In Silly a complete list of the the Literals is (a) Silly args println (b) 3 123 10 "Yes!" (c) 3 123 10 (d) Integer String (e) None of the above 4. In Silly a complete list of the Identifiers is (a) 3 123 10 (b) public class static void int new (c) Silly main String args Integer new x System out println (d) Silly main String args Integer new x System out println public class static void int new (e) None of the above 5. In Silly a complete list of the the keywords is (a) 3 123 10 (b) public class static void int new if (c) Silly main String args Integer new x System out println (d) Silly main String args Integer new x System out println public class static void int new (e) None of the above

CSE 1020.03 page 3 of 12 6. Which output best matches the following code fragment int x = 2; float y = 2.0f; int z = x / 4 * 2; float p = x / 4 * 2; float q = y / 4 * 2; System.out.println(z + " " + p + " " + q); (a) 1 1.0 1.0 (b) 1 1 1 (c) 0 0.0 1.0 (d) 0 1.0 1.0 (e) 0 0.0 0.0 7. Which output best matches the following code fragment byte x = (byte)127; byte y = (byte)(x +256); byte z = (byte)(x + 1); int x1 = 127; int z1 = x1 + 1; char c = (char)('a'+2); System.out.println(y + " " + z + " " + " " + z1 + " " + c); (a) 127-128 128 a (b) -128-128 128 b (c) -128-128 128 b (d) 383 128 128 a2 (e) 127-128 128 c 8. Which output best matches the following code fragment Integer a = new Integer(127); Integer b = a; Integer c = new Integer(127); Integer d = c; c = new Integer(127); System.out.println((a==b) + " " + a.equals(b) + " " + (c==d) + " " + c.equals(d)); (a) false false false false (b) true true true true (c) false true false true (d) true true false true

CSE 1020.03 page 4 of 12 (e) true true true false 9. Which output best matches the following code fragment int sum = 0; for(int i=0;i<5;i++) for(int j=i;j<5;j++) sum++; System.out.println(sum); (a) 0 (b) 1 (c) 3 (d) 25 (e) 15 10. Which output best matches the following code fragment int sum = 0; for(int i=0;i<5;i++) for(int j=i;j<5;j++); sum++; System.out.println(sum); (a) 0 (b) 1 (c) 3 (d) 25 (e) 15 11. Which output best matches the following code fragment int sum = 0; for(int i=0;i<5;i++) if((i / 2) == 1) sum++; System.out.println(sum); (a) 0 (b) 1 (c) 2 (d) 25 (e) 15

CSE 1020.03 page 5 of 12 Consider the following UML diagram that describes part of a grocery experience. A Basket contains Fruit. The methods getfruit(int x) and gettotalfruit() provide an iteration mechanism over the collection of Fruit in the Basket. Each instance of Fruit has an individual weight (accessible via getweight()). Fruit {Abstract + getvolume(): float + tostring(): String + getweight() : float * Basket + getfruit(int x): Fruit + gettotalfruit(): int + get Weight(): Weight Orange + hasseeds() : boolean Pear + hasstem(): boolean 1 Weight + maxweight(): float + emptyweight(): float 12. According to the UML diagram, what methods exist on elements of the class Fruit (a) getvolume(), tostring(), hasseeds(), hasstem() (b) getvolume(), tostring(), hasseeds(), hasstem(), getiterator() (c) getvolume(), tostring(); (d) Fruit is an instance, not a class (e) None of the above 13. According to the UML diagram, how many and which classes are associated with a basket (a) One Fruit and one Weight (b) An equal number of Orange and Pear (0 or more of each) and one Weight (c) An Aggregation of zero or more Fruit and a Composition of one Weight (d) A Composition of zero or more Fruit and Weight (e) An Aggregation of zero of more Fruit and Weight 14. According to the UML diagram, I. It is not possible to create instances of Fruit directly II. Oranges may have seeds and Pears may have stems III. Baskets have both a maximum and empty weight IV. When considered as Fruit, both Oranges and Pears have a volume and weight V. It is not possible to create an instance of Orange or Pear directly

CSE 1020.03 page 6 of 12 (a) All of I through V are true (b) I, II, III and IV only are true (c) None of I through V are true (d) I, II, III and V only are true (e) I, III and V only are true 15. Given the above UML diagram, and a pre-existing Basket b, what does the following code snippet output? float q = 0.0f; int o = 0; int p = 0; for(int i=0;i<b.gettotalfruit();i++) { Fruit f = b.getfruit(i); q += f.getweight(); if(f instanceof Orange) o++; if(f instanceof Pear) p++; System.out.println(q + " " + o + " " + p + " " + (b.gettotalfruit()-o-p)); (a) The weight of the empty basket followed by the number of Orangeʼs, number of Pearʼs, and number of Fruit that are neither Orange or Pear (b) The weight of the Fruit in the basket followed by the number of Orangeʼs, number of Pearʼs, and number of Fruit that are neither Orange or Pear (c) This code makes absolutely no sense in terms of the UML diagram (d) The weight of the Orangeʼs in the basket followed by the number of Orangeʼs, number of Pears and number of Fruit that are neither Orange or Pear (e) The weight of the Pearʼs in the basket followed by the number of Orangeʼs, number of Pearʼs and number of Fruit that are neither Orange or Pear 16. Consider the following program snippet which is a function of some input n float q = 6; for(int i=0;i<n*n*n;i++) q = q * q * 0.05f - q; for(int j=0;j<10000*n;j++) q = q * q * 0.05f - q; for(int j=0;j< 10000000.0/n;j++) q = q * q * 0.05f - q;

CSE 1020.03 page 7 of 12 The big-o running time of this snippet is given by (a) O(1/n) (b) O(n) (c) O(n 3 ) (d) O(log(n)) (e) It is not possible to tell. 17. If a program takes 0.0001 * 2 n + 10 * n 2 + 10000 * log(n) + 10000000 steps to complete, then the big-o running time of the program is (a) O(2 n ) (b) O(n 2 ) (c) O(log(n)) (d) O(1) (e) It is not possible to tell. Consider the following definition of the classes Foo and Bar and what values their methods return public class Foo { public Foo(); // default constructor public static int red(); // returns 2 public int blue(); // returns 3 public int violet(bar x); // returns 0 public int green; public static int orange; public int purple; public class Bar extends Foo { public Bar(); // default constructor public static int red(); // returns 3 public int blue(); // returns 6 public int violet(foo x); // returns 1 public int violet(bar x); // returns 2 public int green; public static int orange; public int yellow; public static final int V = 42;

CSE 1020.03 page 8 of 12 For each of the following questions treat the question in isolation and select the output that would be generated by the code fragment 18. 19. 20. Foo f = new Foo(); f.orange = 3; Foo g = new Foo(); g.orange = 4; System.out.println(f.orange == g.orange); (a) true (b) false (c) The code is invalid as the expression f.orange is invalid (d) The code is invalid as the expression g.orange is invalid (e) The code is invalid as you cannot make two instances of Foo Foo f = new Foo(); f.green = 3; Foo g = new Foo(); g.green = 4; System.out.println(f.green == g.green); (a) true (b) false (c) The code is invalid as the expression f.green is invalid (d) The code is invalid as the expression g.green is invalid (e) The code is invalid as you cannot make two instances of Foo Bar f = new Bar(); f.green = 3; Foo g = f; g.green = 4; System.out.println(f.green + " " + g.green + " " + ((Foo) f).green + " " + ((Bar) g).green); (a) 3 4 4 4 (b) 3 4 3 4 (c) 3 4 4 3 (d) 3 4 3 3

CSE 1020.03 page 9 of 12 21. 22. 23. 24. Bar f = new Bar(); f.orange = 3; Foo g = f; g.orange = 4; System.out.println(f.orange + " " + g.orange + " " + ((Foo) f).orange + " " + ((Bar) g).orange); (a) 3 4 4 4 (b) 3 4 3 4 (c) 3 4 4 3 (d) 3 4 3 3 Bar f = new Bar(); Foo g = f; System.out.println(f.red() + " " + g.red() + " " + ((Foo) f).red() + " " + ((Bar) g).red()); (a) 2 3 2 3 (b) 3 3 3 3 (c) 3 2 2 3 (d) 3 2 3 2 Foo f = new Bar(); Bar g = (Bar) f; System.out.println(f.red() + " " + g.red() + " " + ((Foo) f).red() + " " + ((Bar) g).red()); (a) 2 3 2 3 (b) 3 3 3 3 (c) 3 2 2 3 (d) 3 2 3 2 Bar f = new Bar();

CSE 1020.03 page 10 of 12 Foo g = f; System.out.println(f.blue() + " " + g.blue() + " " + ((Foo) f).blue() + " " + ((Bar) g).blue()); (a) 6 3 3 6 (b) 6 3 6 3 (c) 6 6 6 6 (d) 6 3 3 3 25. Foo f = new Bar(); System.out.println(f.violet(new Bar()) + " " + ((Bar) f).violet(new Bar()) + " " + ((Bar) f).violet(new Foo())); (a) 1 2 0 (b) 2 2 0 (c) 2 2 2 (d) 2 2 1 26. Bar f = new Bar(); f.v = 44; System.out.println(f.V); (a) 44 (b) 42 (c) It is not possible to know (d) The program will not compile 27. Which output best matches the following code fragment Set<String> set = new TreeSet<String>(); String s = ILLUSIONS ; for(int i = 0; i < s.length() ;i++) set.add((new Character(s.charAt(i))).toString()); Iterator<String> it = set.iterator() ; while(it.hasnext()) System.out.print(it.next()); System.out.println();

CSE 1020.03 page 11 of 12 (a) ILLUSIONS (b) ILNOSU (c) ILUSIO (d) USONLI 28. Which output best matches the following code fragment try { System.out.print("A"); throw new RuntimeException("argh"); catch(exception err) { System.out.print("C"); System.out.println("D"); (a) AarghCD (b) AD (c) ACD (d) AarghCD 29. Which output best matches the following code fragment List<String> set = new ArrayList<String>(); String s = "MADAMIMADAM"; for(int i = 0 ;i < s.length();i++) set.add((new Character(s.charAt(i))).toString()); Iterator<String> it = set.iterator(); String v = ""; while(it.hasnext()) v = it.next() + v; System.out.println(v + " " + v.equals(s)); (a) MADAMIMADAM true (b) MADI false (c) Bus error, core dumped (d) I false 30. Which output best matches the following code fragment String s = "Ypu hbvf sebciee uhf fne pf tie eyan"; String v = ""; for(int i=0;i<s.length();i++) {

CSE 1020.03 page 12 of 12 char c = s.charat(i); if(c == ʻ ʻ) v = v + c; else v = v + (char)(c - (i % 2)); System.out.println("" + v.charat(0) + v.charat(4) + v.charat(9) + v.charat(17)); (a) Yz68 (b) FoBa (c) 04917 (d) Yhrt