Good Luck! CSC207, Fall 2012: Quiz 3 Duration 25 minutes Aids allowed: none. Student Number: Lecture Section: L0101. Instructor: Horton

Similar documents
Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:

CSC 207H Fall L Java Quiz Duration 25 minutes Aids allowed: none

No Aids Allowed. Do not turn this page until you have received the signal to start.

ENGLISH Page 1 of 6. EXAM IN COURSE TDT4100 Object-Oriented Programming / IT1104 Programming, Advanced Course. Tuesday 29. Mai

Student Number: Please fill out the identification section above as well as the one on the back page, and read the instructions below. Good Luck!

CMSC 132, Object-Oriented Programming II Summer Lecture 1:

public static boolean isoutside(int min, int max, int value)

public static void negate2(list<integer> t)

Examples. Stack. VideoPlayer

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

No Aids Allowed. Do not turn this page until you have received the signal to start.

Stack Implementation

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

Computer Science CS221 Test 2 Name. 1. Give a definition of the following terms, and include a brief example. a) Big Oh

An Introduction to Systematic Software Testing. Robert France CSU

Introduction to Computer Science II (ITI 1121) Midterm Examination

Object Oriented Software Design - I

EECS2030 Week 7 worksheet Tue Feb 28, 2017

In this lab we will practice creating, throwing and handling exceptions.

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Introduction to Computing II (ITI 1121) Midterm Examination

Midterm Exam (REGULAR SECTION)

CSE 143 SAMPLE MIDTERM

Java Object Oriented Design. CSC207 Fall 2014

CSC 1351: Quiz 6: Sort and Search

CSIS 10B Lab 2 Bags and Stacks

Declarations and Access Control SCJP tips

public class Q extends P { private int num; private int i; P(int n) { public Q() { this.num = n;

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Csci 102: Sample Exam

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

EXAMPLE ANSWERS. EXAM IN COURSE TDT4100 Object-Oriented Programming / IT1104 Programming, Advanced Course. Tuesday 29. Mai

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

Largest Online Community of VU Students

IT 313 Advanced Application Development

Introduction to Computer Science II (CSI 1101)

Observer Pattern. CS580 Advanced Software Engineering October 31, Yu Sun, Ph.D.

Student Number: Lab day:

Interfaces & Generics

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

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

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

Last name:... First name:... Department (if not D-INFK):...

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

Simplest JavaBeans Bean and NetBeans, Part 3 Testing Using Junit.

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 7

are most specifically concerned with

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004

Midterm Exam 2 CS 455, Spring 2015

linaye/gl.html

UNIVERSITY OF TORONTO Faculty of Arts and Science

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

CS 61B Discussion 5: Inheritance II Fall 2014

Solutions to Sample JAC444 Midterm Test

Introduction to Computing II (ITI 1121) Final Examination

COE318 Lecture Notes Week 9 (Oct 31, 2011)

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes

No Aids Allowed. Do not turn this page until you have received the signal to start. Read this entire page or you ll miss the bonus question.

PROGRAMMING FUNDAMENTALS

1.00/ Introduction to Computers and Engineering Problem Solving. Quiz 2 / November 10, 2005

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

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

Computer Science 1 Ah

Cosc 241 Programming and Problem Solving Lecture 9 (26/3/18) Collections and ADTs

Write a program to implement stack or any other data structure in Java ASSIGNMENT NO 15

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)

CS2 Practical 1 CS2A 22/09/2004

CSC207 Quiz 1 Solutions Monday 6 February 2017, 12:15 PM. 1. (A) (B) (C) (D) (E) 7. Nothing, does not run true false

ECSE 321 Assignment 2

CS108, Stanford Handout #3. HW1 CodeCamp

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

Introduction to Computer Science II (ITI 1121) Midterm Examination

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CSCD 326 Data Structures I Stacks

Comp Intermediate Programming EXAM #1 February 16, 2004 Rice University - Instructors: Cox & Nguyen

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

Computer Programming, I. Laboratory Manual. Final Exam Solution

Programming Languages and Techniques (CIS120)

Data Structures (CS 102), Professor Yap Spring 2015 MIDTERM. April 19, 2015

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004

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

THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A

CSE143 Summer 2008 Final Exam Part B KEY August 22, 2008

Code Reuse: Inheritance

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007

Junit Overview. By Ana I. Duncan

Lecture 22: Java. Overall Structure. Classes & Objects. Every statement must end with ';' Carl Kingsford, , Fall 2015

6.005 Elements of Software Construction Fall 2008

CSE 11 Midterm Fall 2008

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Ticket Machine Project(s)

Assignment 5. Introduction

School of Informatics, University of Edinburgh

Programming Languages and Techniques (CIS120)

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

UNIVERSITY OF TORONTO Faculty of Arts and Science

Student Number: Legibly write your name and student number on this page. Legibly write your name on the back page of this exam.

Transcription:

CSC207, Fall 2012: Quiz 3 Duration 25 minutes Aids allowed: none Student Number: Last Name: Lecture Section: L0101 First Name: Instructor: Horton Please fill out the identification section above as well as the one on the back page, and read the instructions below. Good Luck! This quiz consists of 3 questions on 6 pages (including this one). When you receive the signal to start, please make sure that your copy of the quiz is complete. If you use any space for rough work or need to scratch out an answer, circle the part that you want us to mark. # 1: / 5 # 2: / 6 # 3: / 7 TOTAL: /18 Total Pages = 6 Page 1

Question 1. [5 marks] Part (a) [1 mark] In assignment 2, one of the operations you implemented was called product. It s job was to produce the Cartesian product of two tables. Suppose we have a table t with r1 rows and c1 columns, and a table u with r2 rows and c2 columns. Consider the table produced by the expression product(t, u). How many rows would that table have? How many columns would that table have? Part (b) [1 mark] When following the Singleton design pattern, which of the following must you ensure? Check one. There can never be more than one instance Each instance must have exactly one instance variable Each instance must have at most one instance variable There must be a single parent class Part (c) [1 mark] Complete the line of code below to make it print out whether or not a string called ID satisfies the following requirements: (1) it has exactly one dot character (. ), (2) it has nothing but vowels (and at least one) before the dot, and (2) it has nothing but vowels (and at least one) after the dot as well. System.out.println( Pattern.matches("[aeiouAEIOU]+\\.[aeiouAEIOU]+", ID) ); Because you haven t had much chance to practise with Java regex, we were not picky about the backslashes. Part (d) [1 mark] Suppose class Sneetch extends Observer. Which statement is true? Check one. Sneetch inherits a method called update that it must not override Sneetch inherits a method called update that it has the option of overriding Sneetch must implement a method called update Trick question! This is impossible because Part (e) [1 mark] Suppose class Smurf extends Observable. Which statement is true? Check one. Smurf must implement a method called notifyobservers Smurf must not extend anything else Smurf must not implement anything Trick question! This is impossible because Page 2 of 6

Question 2. [6 marks] Consider the following code: public class ExceptionQuestion { // Rest of class Omitted. public int helper(int n) throws InvalidArgumentException { // Body omitted. public boolean dosomething(int n) { return (helper(n) > 0); Part (a) [1 mark] This code can compile in its current form: is that true or false? True False Part (b) [4 marks] Change method dosomething on the copy below so that it returns false if method helper reports that it was given an invalid argument. public boolean dosomething(int n) { return (helper(n) > 0); Suppose that instead of dealing with any possible InvalidArgumentException that helper may throw, we wanted method dosomething to just pass the exception along. Modify the code on the copy below so that it will do that. public boolean dosomething(int n) { return (helper(n) > 0); Part (c) [1 mark] Write class InvalidArgumentException below. Page 3 of 6

Question 3. [7 marks] Consider this very simple stack class. Method bodies have been omitted. public class Stack { * Construct an empty stack. public Stack() { * Make o the new top item on this stack. * * @param o the new top item. public void push(object o) { * Remove and return the top item on this stack. * * @return the top item. public Object pop() { Below is the JUnit code that Netbeans generates for it: public class StackTest { public StackTest() { @BeforeClass public static void setupclass() throws Exception { @AfterClass public static void teardownclass() throws Exception { Page 4 of 6

@Before public void setup() { @After public void teardown() { * Test of push method, of class Stack. @Test public void testpush() { // Body omitted * Test of pop method, of class Stack. @Test public void testpop() { System.out.println("pop"); Stack instance = new Stack(); Object expresult = null; Object result = instance.pop(); assertequals(expresult, result); // TODO review the generated test code and remove the default call to fail. fail("the test case is a prototype."); Part (a) [3 marks] Modify the code for method testpop so that it tests the behaviour of pop on a stack with one element. Part (b) [4 marks] Suppose you wanted to create the following fixture to be available and in the following state for every test case: a stack of three integers, 10, 20 and 30, with 10 on the bottom and 30 on the top. Modify the code above to make this happen. Page 5 of 6

Last Name: First Name: Some parts of the Java API: Class Pattern: static boolean matches(string regex, CharSequence input) Compiles the given regular expression and attempts to match the given input against it. Interface Observer: void update(observable o, Object arg) This method is called whenever the observed object is changed. Class Observable: void addobserver(observer o) Adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set. void notifyobservers() If this object has changed, as indicated by the haschanged method, then notify all of its observers and then call the clearchanged method to indicate that this object has no longer changed. Total Pages = 6 Page 6 End of Examination