SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

Similar documents
Throughout the exam, write concisely and underline key words or phrases. Have fun! Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031.

1. (5 points) In your own words, describe what an instance is.

Midterm assessment - MAKEUP Fall 2010

RAIK 183H Examination 2 Solution. November 11, 2013

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

RAIK 183H Examination 2 Solution. November 10, 2014

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

MIT AITI Swing Event Model Lecture 17

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

Window Interfaces Using Swing Objects

Part I: Learn Common Graphics Components

Agenda. Container and Component

Graphical User Interface (Part-1) Supplementary Material for CPSC 233

CS 11 java track: lecture 3

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

CSCI 201L Midterm Written Fall % of course grade

CMP-326 Exam 2 Spring 2018 Solutions Question 1. Version 1. Version 2

Window Interfaces Using Swing. Chapter 12

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Object Oriented Design & Patterns. Part 1

AP CS Unit 11: Graphics and Events

Packages: Putting Classes Together

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

CS 180 Final Exam Review 12/(11, 12)/08

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Window Interfaces Using Swing Objects

CSCI 201L Midterm Written SOLUTION Fall % of course grade

Final Exam CS 251, Intermediate Programming December 13, 2017

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Swing from A to Z Some Simple Components. Preface

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

PART1: Choose the correct answer and write it on the answer sheet:

Fundamentals of Object Oriented Programming

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

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

Introduction to the JAVA UI classes Advanced HCI IAT351

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton

Graphical User Interfaces (GUIs)

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Do not turn to the next page until the start of the exam.

Introduction This assignment will ask that you write a simple graphical user interface (GUI).

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

CS Exam 3 - Spring 2010

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

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions

CSC207 Week 4. Larry Zhang

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

CS Exam 3 - Spring 2010

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

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

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

Come & Join Us at VUSTUDENTS.net

Class 16: The Swing Event Model

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Part 3: Graphical User Interface (GUI) & Java Applets

CS108, Stanford Handout #22. Thread 3 GUI

1.00/ Introduction to Computers and Engineering Problem Solving. Quiz 2 / November 5, 2004

Java. GUI building with the AWT

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

CSIS 10A Assignment 7 SOLUTIONS

CS180 Review. Recitation Week 15

Lecture 5: Java Graphics

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

Java Help Files. by Peter Lavin. May 22, 2004

More on Exception Handling

Starting Out with Java: From Control Structures Through Objects Sixth Edition

FirstSwingFrame.java Page 1 of 1

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

The University of Melbourne Department of Computer Science and Software Engineering Software Design Semester 2, 2003

Graphical User Interfaces. Comp 152

More on Exception Handling

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

CS 251 Intermediate Programming GUIs: Components and Layout

CS Exam 1 Review Suggestions

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

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Graphical User Interfaces in Java - SWING

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

H212 Introduction to Software Systems Honors

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

CS 1316 Exam 3 Fall 2009

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

UTM CSC207: Midterm Examination October 28, 2011

University of Cape Town Department of Computer Science. Computer Science CSC117F Solutions

Graphical Interfaces

Graphical Interfaces

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

2. (True/False) All methods in an interface must be declared public.

No SVN checkout today. Object-Oriented Design

Transcription:

SE1021 Exam 2 Name: You may use a note-sheet for this exam. But all answers should be your own, not from slides or text. Review all questions before you get started. The exam is printed single-sided. Write your name on each page. You may do this before the exam if you don t peek at the questions. When returning your exam, place your note-sheet on top. Page 1: This cover Page 2 (Multiple choice): 10pts Page 3 (Multiple choice): 10pts Page 4 (Short answer): 20 pts Page 5 (Code completion): 15 pts Page 6 (Code comprehension): 15 pts Page 7 (Code tracing and writing): 20 pts Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031. Page 1 of 7

1. (4 pts) Multiple Choice a. Would you extend or implement JFrame? i. extend ii. implement b. Would you extend or implement ActionListener? i. extend ii. implement c. Would you extend or implement Exception? i. extend ii. implement d. Which provides a specific response to an event? i. the source object ii. the listener object 2. (6 pts.) Multiple Choice a. Select the option which completes the following code-snippet so that when the button is clicked, the listener can handle the method. JButton b = new JButton( b ); i. addeventlistener(listener); ii. addactionlistener(listener); iii. b.addeventlistener(listener); iv. b.addactionlistener(listener); b. Which one of the following will compile? i. public abstract class A { public abstract void fun(); ii. public abstract class A { public abstract void fun() { iii. public class A { public abstract void fun(); iv. public class A { public abstract void fun() { c. Which flow manager would be best for designing this layout: i. FlowLayout ii. BorderLayout iii. BoxLayout iv. GridLayout Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031. Page 2 of 7

3. (10 pts.) See the UML diagram above. Select one. a. The relationship between Toy and Floor is i. Composition ii. Aggregation iii. Inner-class iv. Inheritance v. Implementation b. The relationship between JumpButtonListener and ActionFigure is i. Composition ii. Aggregation iii. Inner-class iv. Inheritance v. Implementation c. Which one of the following statements is valid? i. Toy t = new Block(new Floor()); ii. Toy t = new Toy(); iii. Block b = new Block(); iv. Block b = new Toy(new Floor()); d. Which one of the following statements is valid? i. FlatTop t = new FlatTop(new Floor()); ii. FlatTop t = new SquareBlock(); iii. SquareBlock f = new SquareBlock(new Floor()); iv. SquareBlock f = new FlatTop(); e. Which one of the following method-calls is valid? Assume b and b2 are both SquareBlocks and f is a Floor. i. b.acceptontop(new FlatTop()) ii. b.acceptontop(b2) iii. b.acceptontop(f) iv. b.acceptontop(new Toy(f)) Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031. Page 3 of 7

4. [20 pts.] Answer clearly & concisely a. (3 pts.) Consider this code: public abstract class Shape { public abstract void draw(); // In another file public ExamFun { public abstract void drawshapes(shape shape1, Shape shape2) { shape1.draw(); shape2.draw(); If used correctly with other code, this example will both compile and run. How is this possible, since Shape does not supply a body for the draw method? b. (3pts.) Name two Swing classes that act as event sources. c. (3 pts.) While implementing an actionperformed method, we could use e.getsource().equals(r1) instead of e.getsource() == r1 where r1 is a reference to one of the event sources in our program. Why might the.equals solution return true even though == returns false? d. (3 pts.) What happens if an unchecked exception is thrown but never caught? e. (4 pts.) What are two differences between an anonymous inner class and a regular inner class? f. (4 pts.) On which line and in which method did the error occur? What happened? Exception in thread "AWT-EventQueue-0" java.lang.arithmeticexception: / by zero at shapes.ellipse.draw(ellipse.java:36) at shapes.shapemanager.draw(shapemanager.java:113) at ui.drawingprogramui.paint(drawingprogramui.java:133) Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031. Page 4 of 7

5. (15 pts) The following code compiles and runs, but the buttons don t do anything when you click on them. Fix the problem so the program responds to both buttons. // You can assume these are correct import... public class FunGui extends JFrame { JButton b1 = new JButton("press me"); JButton b2 = new JButton("press me"); JLabel label = new JLabel("The button pressed will be displayed here."); public FunGui() { settitle("fun GUI"); setlayout(new FlowLayout()); b1 = new JButton("press me"); b2 = new JButton("press me"); label = new JLabel("The button pressed will be displayed here."); add(b1); add(b2); add(label); pack(); setvisible(true); public void actionperformed(actionevent e) { if(e.getsource() == b1) { label.settext("button 1 pressed"); else if(e.getsource() == b2) { label.settext("button 2 pressed"); public static void main(string[] args) { new FunGui(); Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031. Page 5 of 7

6. [15 pts.] Consider the code below: public static void main(string[] args) { String str = JOptionPane.showInputDialog(null,"Enter something"); try { int i = Integer.parseInt(str); int ratio = 10/i; System.out.println("ratio: "+ratio); catch (ArithmeticException e) { System.out.println("ouch"); catch (NumberFormatException e) { System.out.println("eek"); System.out.println("done"); a. (5 pts.) How can the user get the program to print ratio: 5? b. (5 pts.) How can the user get the program to print eek? c. (5 pts.) What can the user enter, if anything, that would cause the program to not print done? Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031. Page 6 of 7

7. (10 pts.) What does the following code print? public class A { public void m() { System.out.print("1 "); public void m(int argument) { System.out.print("2 "); System.out.print(argument+ " "); public class B extends A { public void m() { this.m(101); System.out.print("3 "); public void m(int argument) { super.m(); System.out.print("4 "); System.out.print(argument+ " "); public static void main(string[] ignored) { B b = new B(); b.m(); 8. (10 pts.) Create a customized class, ExamException, that can be thrown by the following command: throw new ExamException(); Users should not have to explicitly handle this exception. Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031. Page 7 of 7