CSE wi Final Exam 3/12/18. Name UW ID#

Similar documents
CSE wi Final Exam 3/12/18 Sample Solution

CSE 331 Final Exam 3/12/12

CSE 331 Final Exam 6/7/16

CSE 331 Final Exam 6/5/17. Name UW ID#

CSE 331 Final Exam 6/10/14

CSE 331 Final Exam 12/9/13

CSE wi Midterm Exam 2/8/18. Name UW ID #

CSE331 Winter 2014, Final Examination March 17, 2014 Please do not turn the page until 8:30. Rules:

CSE 331 Final Exam 3/16/15 Sample Solution

CSE 331 Final Exam 6/5/17 Sample Solution

CSE 331 Final Exam 3/18/13

CSE 331 Midterm Exam 2/13/12

CSE 331 Final Exam 6/7/16 Sample Solution

CSE 331 Final Exam 12/14/15 Sample Solution. Question 1. (20 points, 1 each) Warmup. For each statement, circle T if it is true and F if it is false.

CSE 331 Spring 2018 Midterm

CSE331 Fall 2014, Final Examination December 9, 2014 Please do not turn the page until 2:30. Rules:

CSE 331 Midterm Exam Sample Solution 2/18/15

CSE331 Winter 2014, Midterm Examination February 12, 2014

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

Section 10: Design Patterns 2

CSE 333 Midterm Exam July 24, Name UW ID#

CSE wi Midterm Exam 2/8/18 Sample Solution

CSE331 Spring 2015, Final Examination June 8, 2015

Exam Review. CSE 331 Section 10 12/6/12. Slides by Kellen Donohue with material from Mike Ernst

CSE 333 Midterm Exam 7/25/16. Name UW ID#

CSE 333 Final Exam 3/19/14

Assignment 2. Application Development

First Name: AITI 2004: Exam 2 July 19, 2004

CSE331 Winter 2014, Midterm Examination February 12, 2014

CSE 333 Midterm Exam 5/10/13

Exam 2 CSCI 2600 Principles of Software November 3, 2015

Soda Machine Laboratory

CSE 333 Midterm Exam 2/14/14

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

CSE 333 Midterm Exam 7/29/13

6.005 Elements of Software Construction Fall 2008

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

CSE 143 Au04 Midterm 1 Page 1 of 9

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Object-oriented programming in Java (2)

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

CSE 143 Sp03 Final Exam Sample Solution Page 1 of 13

First Name: AITI 2004: Exam 2 July 19, 2004

CSE351 Winter 2016, Final Examination March 16, 2016

INSTRUCTIONS TO CANDIDATES

CSE 331 Midterm Exam 11/9/15 Sample Solution

COP 3330 Final Exam Review

Final Exam. COMP Summer I June 26, points

About this exam review

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

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

Use the scantron sheet to enter the answer to questions (pages 1-6)

Programming via Java Subclasses

CPSC 310: Sample Final Exam Study Questions 2014S1 (These are in addition to the Study Questions listed at the end of some lectures)

Design Patterns: State, Bridge, Visitor

CSE 131 Introduction to Computer Science Fall Exam II

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

CMSC 331 Second Midterm Exam

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

CSE 331 Winter 2016 Midterm Solution

Final Examination Semester 2 / Year 2012

Prelim 2. CS 2110, 5:30 PM, November 17, 2016

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

CSE 401 Final Exam. March 14, 2017 Happy π Day! (3/14) This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,...

CIS 162 Project 1 Business Card Section 04 (Kurmas)

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

Full file at Chapter 2 - Inheritance and Exception Handling

Introduction to Programming Using Java (98-388)

Midterm assessment - MAKEUP Fall 2010

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

Beyond CSE143. What s Left To Do? Templates. Using Templates. A Template Class. A Problem with Reusing Code CSE 143

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

RAIK 183H Examination 2 Solution. November 11, 2013

UMBC CMSC 331 Final Exam

CS 11 java track: lecture 3

CSE 331 Midterm Exam Sample Solution 2/13/12

CSE 333 Midterm Exam 2/12/16. Name UW ID#

Example: Count of Points

Review sheet for Final Exam (List of objectives for this course)

Final Examination Semester 2 / Year 2011

Total Score /1 /20 /41 /15 /23 Grader

CSE 331 Software Design & Implementation

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

Part I: Short Answer (12 questions, 65 points total)

CSE 333 Midterm Exam 7/22/12

CS 342 Software Design Spring 2018 Term Project Part II Development of Question, Answer, and Exam Classes

CS 113 PRACTICE FINAL

Java Swing Introduction

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM

Comp Intermediate Programming EXAM #2 March 30, 2005 Rice University - Instructors: Cox & Nguyen

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO

CSE 131 Introduction to Computer Science Fall Exam II

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

Transcription:

Name UW ID# There are 13 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed electronics, closed telepathy, etc. Many of the questions have short solutions, even if the question is somewhat long. Don t be alarmed. If you don t remember the exact syntax of some command or the format of a command s output, make the best attempt you can. We will make allowances when grading. Please be sure to write your answers in the spaces provided. Do not write on the backs of pages or on pages that indicate that no answers should be written there. These will not be scanned for grading. An extra blank page is provided at the end of the exam if you need additional space for your answers. Relax, you are here to learn. Please wait to turn the page until everyone is told to begin. Score / 100 1. / 8 2. / 8 3. / 8 4. / 12 5. / 8 6. / 10 8. / 10 9. / 10 10. / 5 11. / 6 12. / 5 13. / 2 7. / 8 Page 1 of 15

Question 1. (8 points, 2 each) Equality. Recall that there are several different notions of object equality that we ve encountered this quarter. In particular, we have the following three: Reference equality: two objects are reference equivalent (==) if they are the same object. Behavioral equality: two objects are behaviorally equivalent if there is no sequence of operations (other than ==) that can distinguish them. Observational equality: two objects are observationally equivalent if there is no sequence of observer operations that can distinguish them (other than ==) Now suppose we have a class Thing that implements immutable objects with appropriate equals and hashcode methods. Consider the following code fragment. We would like to know, for each of the assertions P, Q, R, and S, what we can conclude at that point in the program. final Thing x =...; final Thing y =...; if (x.hashcode() == y.hashcode()) { { P else { { Q if (x.equals(y)) { { R else { { S For each of the assertions P, Q, R, and S, indicate, by writing in the blank, the roman numeral of the strongest assertion what we can conclude at that point in the program: i. x is equal to y (by reference) ii. x is equivalent to y (observationally or behaviorally or both) iii. x is not equal to y (by reference) iv. x is not equivalent to y (observationally or behaviorally or both) v. true (the weakest possible assertion) P Q R S Page 2 of 15

Question 2. (8 points, 4 each) Debugging. Use the terms defect, error, and failure to answer the following questions in 1 or 2 sentences. (a) Define debugging in terms of these concepts. (b) What is the purpose of adding an assert statement to a program? Question 3. (8 points, 4 each) More debugging. Also answer in 1 or 2 sentences each. (a) Suppose we have a program that exhibits a failure only when assertions are disabled and executes correctly if assertions are enabled. What is the most likely reason this could happen? (b) A first step in debugging is to create a small test that demonstrates the failure. Why should we add that test case to the regression-test suite once we ve fixed the bug? After all, the bug is fixed and all the tests pass now. Page 3 of 15

The next several questions concern the following classes. Please remove this page from the exam and use it to answer questions on the next few pages. Do not include this page in your submitted exam. It will not be graded. Consider the following classes: abstract class Bird { public abstract void speak(); public void move() { System.out.println("flap flap!"); public void move(int n) { move(); speak(); class Canary extends Bird { public void speak() { System.out.println("chirp!"); public void move(int n) { speak(); speak(); class Duck extends Bird { public void speak() { System.out.println("quack!"); class RubberDuck extends Duck { public void speak() { System.out.println("squeak!"); public void move() { speak(); swim(); public void swim() { System.out.println("paddle!"); Please remove this page from the exam and use it to answer questions on the next few pages. Do not include this page in your submitted exam. It will not be graded. Page 4 of 15

Question 4. (12 points, 2 points each). Here are several groups of statements that might be found in a program that uses the classes on the previous page. For each group, if the statements compile and execute successfully without any errors, write the output that is produced. If there is an error, explain in a sentence what is wrong. (a) Bird b = new Bird(); b.move(); (b) Bird b = new Canary(); b.move(17); (c) Bird b = new Duck(); b.move(42); (d) Bird b = new RubberDuck(); b.move(3); (e) Duck donald = new RubberDuck(); donald.swim(); (f) Duck donald = new RubberDuck(); donald.move(); Page 5 of 15

Question 5. (8 points) More Birds. We d now like to create a class to hold a collection of Birds (an aviary). Here are some basic parts of the class definition: // a collection of Birds public class Aviary { private List<Bird> birds; private static Random r = new Random(); // construct an empty Aviary public Aviary() { birds = new ArrayList<Bird>(); // add one Bird to the Aviary public void add(bird b) { birds.add(b); // return a random Bird from the Aviary public Bird get() { return birds.get(r.nextint(birds.size())); (a) (2 points) We would like to add a method to this class to be able to add any collection of Birds to an Aviary. Fill in the most general type possible for the flock parameter of the addall method below so it will accept any Java Collection containing Birds or objects that are from any subclasses of Birds. // add a Collection of Birds to the Aviary public void addall( flock) { birds.addall(flock); (continued next page) Page 6 of 15

Question 5. (cont.) For some applications we d like to create a collection of Birds that can hold only Ducks or subtypes of Ducks. Suppose we create the following class: class Pond extends Aviary { public void add(duck d) { super.add(d); (b) (2 points) Does this new add method override or overload the add method inherited from Aviary, or does it cause some sort of error when we try to compile this new class? (c) (2 points) Is class Pond a Java subtype of Aviary? Explain your answer in 1 or 2 sentences. (d) (2 points) Is class Pond a true subtype of Aviary? Explain your answer in 1 or 2 sentences. Page 7 of 15

Question 6. (10 points, 1 each) Generics and containers. Recall our Bird class hierarchy: class Bird class Canary extends Bird class Duck extends Bird class RubberDuck extends Duck Now suppose we have the following variables: Object o; Bird b; Canary c; Duck d; RubberDuck r; List<? extends Bird> leb; List<? extends Duck> led; List<? super Duck> lsd; For each of the following, circle OK if the statement has correct Java types and will compile without type-checking errors; circle ERROR if there is some sort of type error. OK ERROR led.add(d); OK ERROR leb.add(o); OK ERROR lsd.add(r); OK ERROR lsd.add(o); OK ERROR leb.add(null); OK ERROR d = lsd.get(1); OK ERROR d = led.get(1); OK ERROR b = leb.get(1); OK ERROR o = led.get(1); OK ERROR b = lsd.get(1); Page 8 of 15

Question 7. (8 points, 2 each) Comparing specifications. Recall that a prime number n is a natural number (integer) that is greater than 1 and that cannot be written as the product of two natural numbers that are both smaller than n. Consider the following specifications. All values (parameter and return values) are integers. S1: @param x input number @requires x > 0 @return the largest prime number that is less than x @throws NoSuchPrimeNumberException if there is no prime number that is less than x S2: @param x input number @requires x > 2 @return the largest prime number that is less than x S3: @param x input number @requires x > 0 @return the largest prime number that is less than or equal to x @throws NoSuchPrimeNumberException if there is no prime number that is less than or equal to x S4: @param x input number @return the largest prime number that is less than x @throws NoSuchPrimeNumberException if there is no prime number that is less than x In the answers below, you do not need to include each specification in the list of ones that are stronger or equivalent to itself. Just list the other specifications that are stronger or equivalent (if any). If there are no other specifications in an answer, write none. (a) List all of the specification that are stronger than or equivalent to S1. (b) List all of the specification that are stronger than or equivalent to S2. (c) List all of the specification that are stronger than or equivalent to S3. (d) List all of the specification that are stronger than or equivalent to S4. Page 9 of 15

Question 8. (10 points) Java graphics. One of the new interns has been trying to learn Swing so they can work on an old application program that uses it. The intern has come up with this program, which is supposed to draw a red oval that almost fills a window. Unfortunately, when the program is run nothing appears to happen. We've rechecked the method calls that compute the size of the oval and we're sure that those are right the size is computed correctly, and the width and height parameters are in the right order. Something else is causing the problem. Your job is to modify, delete, or add the necessary code to fix the program so the output will look like the drawing to the left (i.e., the expected picture). There might be multiple bugs. import java.awt.*; import javax.swing.*; public class DrawOval { public static void main(string[] args) { JFrame frame = new JFrame("An Oval"); frame.setdefaultcloseoperation(jframe.exit_on_close); JPanel panel = new Oval(); panel.setpreferredsize(new Dimension(300,200)); panel.paintcomponent(new Graphics2D()); public class Oval extends JPanel { @Override public void paintcomponent(graphics g) { super.paintcomponent(g); Graphics2D g2 = (Graphics2D) g; int height = getheight(); int width = getwidth(); // draw a red oval g2.setcolor(color.red); g2.filloval(10,10,width-20,height-20); Page 10 of 15

Question 9. (10 points, 2 each) Design patterns. Here is an alphabetical list some design patterns we discussed this quarter. Note that some of these may be more specific instances of other patterns. Adapter, Builder, Composite, Decorator, Dependency Injection, Factory, Iterator, Intern, Interpreter, Model-View-Controller (MVC), Observer, Procedural, Prototype, Proxy, Singleton, Visitor For each statement below, list all of the design patterns from the list above that meet the description. Each answer might include one or more design patterns, and for full credit you must list all of them. There is at least one design pattern that fits each of these descriptions. (a) The pattern involves a class where most of the functionality is provided by one other class. (b) The pattern is a way to implement the Procedural pattern without using instanceof tests. (c) The pattern should only be used only for immutable classes. (d) The pattern is fundamental to the way that Java s Graphical User Interface (GUI) libraries are organized. (e) It is necessary to make constructors private if we want to require that clients use this pattern. Page 11 of 15

Question 10. (5 points) Build tools. All modern development environments (IDEs) like Eclipse, Intellij, Visual Studio, and so forth have built-in tools to automatically build and rebuild executable programs as code is added or changed in a project. Yet almost all projects use an external build tool like ant or make to do the actual building, bypassing the provided tools in the IDE. Why? Why not just simplify things by using the IDE build tools? (Be brief a couple of sentences ought to be enough.) Question 11. (6 points) Version control. A major reason for using version control systems like git is to allow many programmers to collaborate on a project. But even if you are working on a project by yourself, using a version control system can be useful. Describe two distinct benefits of using a version control system for a project even if you are working by yourself. One or two sentences each should be enough. (i) (ii) Page 12 of 15

A CSE 331 18wi Final Exam 3/12/18 B C D Question 12. (5 points, 1 point each) System integration. When building a large system, there are two common strategies for the order in which to implement and test the different parts of the system: top-down and bottom-up. These two strategies have different characteristics and strengths. E F G For each of the following, circle top-down or bottom-up if that strategy is the best match to the description. If both strategies are a good match or are effective at solving the problem, circle both. If neither strategy matches the description or neither is particularly effective at solving the problem, circle neither. (a) Best at catching major design or usability errors early top-down bottom-up both neither (b) When a new module is added, the number of modules it interacts with and potential number of places to look for an error is larger top-down bottom-up both neither (c) Requires building stubs, sometimes also known as mock objects top-down bottom-up both neither (d) Best at showing visible or tangible progress to clients and other team members top-down bottom-up both neither (e) Best at uncovering infrastructure efficiency issues early top-down bottom-up both neither Page 13 of 15

Question 13. (2 free points) (All reasonable answers receive the points. All answers are reasonable as long as there is an answer. J ) Draw a picture of something that you plan to do during your spring break! Congratulations from the CSE 331 staff! Have a great spring break!! Page 14 of 15

Additional space for answers if needed. Please indicate clearly which questions you are answering here, and also be sure to indicate on the original page that the rest of the answer can be found here. Page 15 of 15