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

Similar documents
Object Oriented Programming 2013/14. Final Exam June 20, 2014

Object Oriented Programming 2012/13. Final Exam June 27th, 2013

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

Object Oriented Programming 2012/13. Final Exam June 12th, 2013

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

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

Exam Duration: 2hrs and 30min Software Design

CS 113 PRACTICE FINAL

Fundamentals of Object Oriented Programming

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Final Exam. COMP Summer I June 26, points

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

Midterm Exam CS 251, Intermediate Programming March 6, 2015

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

CMSC 331 Second Midterm Exam

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

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

EECS2030 Week 7 worksheet Tue Feb 28, 2017

Selected Questions from by Nageshwara Rao

CMPSCI 187 Midterm 1 (Feb 17, 2016)

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger and Josh Hug

CS 61B Discussion 5: Inheritance II Fall 2014

PROGRAMMING FUNDAMENTALS

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

ITI Introduction to Computing II

Computer Science 300 Sample Exam Today s Date 100 points (XX% of final grade) Instructor Name(s) (Family) Last Name: (Given) First Name:

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Full file at Chapter 2 - Inheritance and Exception Handling

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

1Z0-808 oracle. Number: 1Z0-808 Passing Score: 800 Time Limit: 120 min.

ITI Introduction to Computing II

Chapter 11: Collections and Maps

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

CS 1331 Fall 2016 Exam 3 Part 1 ANSWER KEY

National University. Faculty of Computer Since and Technology Object Oriented Programming

More on Exception Handling

CS121/IS223. Object Reference Variables. Dr Olly Gotel

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

Java Identifiers, Data Types & Variables

CSE 143 Java. Exceptions 1/25/

Object Oriented Programming Exception Handling

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)

Recap of OO concepts. Objects, classes, methods and more. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Programming - 2. Common Errors

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

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Computer Science II Data Structures

Checked and Unchecked Exceptions in Java

Exceptions & Miscellaneous Lecture 17

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1

Selected Java Topics

COMP-202 Unit 9: Exceptions

COE318 Lecture Notes Week 10 (Nov 7, 2011)

CSCI 355 LAB #2 Spring 2004

Programming II (CS300)

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

Self-test Java Programming

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1

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

COP 3330 Final Exam Review

FAQ: Classes & Objects

Rules and syntax for inheritance. The boring stuff

CS 314 Exam 1 Fall 2016

Computer Programming, I. Laboratory Manual. Final Exam Solution


Introduction to Java. Handout-3a. cs402 - Spring

Informatik II (D-ITET) Tutorial 6

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

COMP1008 Exceptions. Runtime Error

Programming II (CS300)

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

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

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

Tutorial 2: Validating Documents with DTDs

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

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

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

COMP200 EXCEPTIONS. OOP using Java, based on slides by Shayan Javed

Exception-Handling Overview

1.00 Lecture 4. Promotion

COMP 213. Advanced Object-oriented Programming. Lecture 17. Exceptions

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5

The design of an ADT should evolve naturally during the problem-solving process Questions to ask when designing an ADT

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

More on Exception Handling

2.6 Error, exception and event handling

Java Errors and Exceptions. Because Murphy s Law never fails

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

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws

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

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

CSCI 355 Lab #2 Spring 2007

Collections Algorithms

F I N A L E X A M I N A T I O N

b. Suppose you enter input from the console, when you run the program. What is the output?

Topic 5: Abstract Classes & Interfaces

Tutorial 8 Date: 15/04/2014

Instruction to students:

Final Exam Practice. Partial credit will be awarded.

Transcription:

Object Oriented Programming 2015/16 Final Exam June 17, 2016 Directions (read carefully): CLEARLY print your name and ID on every page. The exam contains 8 pages divided into 4 parts. Make sure you have a complete exam. The point value of each problem is indicated next to the problem and below. You have two hours. It is wise to skim all the problems before beginning, to best plan your time. This is a closed book exam. No notes of any kind are allowed. Do all work in the space provided, using the backs of sheets if necessary. Over the table it should ONLY be this exam, a pen and an ID. Turn off the mobile phone. The use of a mobile phone annuls the exam. Part Problem Description Page Marks I 1 a) b) UML 2 1.5 II 2 a) b) c) d) e) Java development 3 3.0 3 a) b) c) d) e) Java multiple choice 6 2.5 4 Java miscellaneous 7 1.0 III 5 XML 8 1.0 IV 6 Swing 8 1.0 Total 10.0 Page 1

Part I -- UML (1.5 marks) 1 Companies consist of departments and offices. Each company has a name. Departments are located in one or more offices. Offices contain an address and one or more departments. One office in a company acts as headquarter. Each department has a name and a manager who is recruited from the set of employees. The employees contain a name and a title, which can only be accessed/updated by getters/setters. The employees are associated with the department they work in. Note: If the company ceases to exist then the offices and departments should also be erased. a) [1.0 mark] Define the UML class diagram for the presented problem. Page 2

b) [0.5 marks] Define an UML object diagram considering a company with an office and a headquarter. Set all needed attributes/associations with some dummy values. Part II -- Java (6.5 marks) 2 Consider a class Pipe with two private fields, diameter (of type double) and number (of type integer), and a public constant field named TOLERANCE, defined as 10E-2. Provide an implementation of class Pipe, with two different ways to compare pipes: one compares pipes by their diameter, up to the TOLERANCE value, and the other compares pipes by the number of pipes. Note: The only types and methods you can use from java package are: - java.lang.comparable with method public int compareto(t obj); - java.util.comparator with method public int compare(t obj1, T obj2); and - java.util.arrays with methods: - public static void sort(object[] a); and - static <T> void sort(t[] a, Comparator<? super T> c). a) [0.5 marks] Provide an implementation of the Pipe class. b) [0.75 marks] Provide the pipe comparison by their diameter. c) [0.75 marks] Provide the pipe comparison by number of pipes. d) [0.5 marks] Provide a main method in a Main class where five pipes are built and stored in an array of pipes. e) [0.5 marks] Within the main method sort the array of pipes according to the two criteria previously implemented and print the result to the terminal. Page 3

public class Pipe implements Comparable<Pipe>{ private double diameter; private int numberofpipes; public static final double TOLERANCE= 10E-15; public Pipe(double diameter, int numberofpipes) { this.diameter = diameter; this.numberofpipes = numberofpipes; public double getdiameter() { return diameter; public int getnumberofpipes() { return numberofpipes; @Override public int compareto(pipe other) { if (Math.abs(diameter - other.diameter) < TOLERANCE) return 0; if (diameter < other.diameter) return -1; return 1; public String tostring() { return("diameter: " + diameter + " number: " + numberofpipes); public class PipeComparator implements Comparator<Pipe> { @Override public int compare(pipe o1, Pipe o2) { return o2.getnumberofpipes()-o1.getnumberofpipes(); public class Main { public static void main(string[] args) { PipeComparator comp = new PipeComparator(); Pipe[] pipes = new Pipe[5]; pipes[0] = new Pipe(0.27, 1); pipes[1] = new Pipe(0.15, 3); pipes[2] = new Pipe(0.25, 7); pipes[3] = new Pipe(0.26, 16); pipes[4] = new Pipe(0.23, 4); //Sorting pipes in an array (with the Comparable) Arrays.sort(pipes); System.out.println("*** Array - Sorting with the Comparable"); for (Pipe p: pipes) System.out.println(p); System.out.println(); //Sorting pipes in an array with a Comparator Arrays.sort(pipes, comp); System.out.println("*** Array - Sorting with the Comparator"); for (Pipe p: pipes) System.out.println(p); Page 4

Page 5

3 Fill the answers of multiple-choice questions in the following table (use only capital letters). If you want to correct your answer scratch out and write the correct answer. Each correct question is marked 0.5 points. A question not answered is marked 0 points, whereas a wrong answer discounts 0.2 points. If you think NONE of the options are correct, write NONE. Question a) b) c) d) e) Answer D A B D D a) [0.5 marks] Let int x=8, what is the output of System.out.println(++x * 3 + "," + x)? A. 24,8 B. 24,9 C. 27,8 D. 27,9 E. It does not compile b) [0.5 marks] Which of these is necessary to specify at time of matrix-array initialization? A. Row B. Column C. Both row and column D. None of the mentioned E. It depends on the operating system c) [0.5 marks] What is the size of a char variable in Java? A. 1 byte B. 2 bytes C. 4 bytes D. It depends on the compiler settings E. It depends on the operating system d) [0.5 marks] Let lli1 and lli2 be both a LinkedList<Integer> with values {0,1,2 and {3,4,5, respectively. What is the output from the following code? A. [0,1,2][3,5] B. [0,1,2][4,5] C. [0,1][3,5] D. [0,1][4,5] E. The code throws an exception Iterator<Integer> it1 = lli1.iterator(); Iterator<Integer> it2 = lli2.iterator(); it1.next(); it1.next(); it1.next(); it2.next(); it1.remove(); it2.remove(); System.out.print(lli1); System.out.println(lli2); Page 6

e) [0.5 marks] What is the value of x after two objects of type Xpto are built? A. 0 B. 1 C. 2 D. 3 E. None of the previous public Xpto { public static int x=0; static { x=1; public Xpto() {x++; 4 [1.0 marks] What are the differences between checked and unchecked exceptions in java? Checked exceptions (CE): - In this case the compiler checks the exceptions a method declares to throw. So, a method is obliged to establish a policy for all checked exceptions thrown by its implementation, either by passing the checked exception further up the stack, or by handling it somehow. - CEs are subclasses of Exception. - CEs represent conditions that are reasonably expected to occur, typically representing invalid conditions in areas outside the immediate control of the program (invalid user input, etc). Unchecked exceptions (UE): - The compiler does not check for these exceptions, and so a method is not obliged to establish a policy for the unchecked exceptions thrown by its implementation (and they almost always do not do so). - UEs are subclasses of RuntimeException. - UEs represent conditions that generally reflect errors in the program s logic and cannot be reasonably recovered from at run time (e.g. NullPointerException, ArrayIndexOutOfBound). Page 7

Part III -- XML (1 mark) 5 [1.0 marks] Consider the problem presented in Part I-1.a). Present a DTD and XML document, with XML elements and attributes, to store all information needed. Use dummy values in the XML. <?xml version="1.0"?> <!DOCTYPE Company [ <!ELEMENT Company (Office+, Headquarter, Department+)> <!ATTLIST Company cname NMTOKEN #REQUIRED> <!ELEMENT Office (Address, Departments)> <!ELEMENT Headquarter (Address, Departments)> <!ELEMENT Department (Employee+)> <!ATTLIST Department name ID #REQUIRED> <!ELEMENT Address (#PCDATA)> <!ELEMENT Departments EMPTY> <!ATTLIST Departments deps IDREFS #IMPLIED> <!ELEMENT Employee (#PCDATA)> <!ATTLIST Employee ename NMTOKEN #REQUIRED> <!ATTLIST Employee manager (true false) "false"> ]> <Company cname="galp"> <Office> <Address>Porto</Address> <Departments deps="d2"/> </Office> <Headquarter> <Address>Lisboa</Address> <Departments deps="d1 D2"/> </Headquarter> <Department name="d1"> <Employee ename="joao_silva" manager="true">ceo</employee> <Employee ename="ana_silva">cto</employee> </Department> <Department name="d2"> <Employee ename="joao_sales" manager="true">rd</employee> <Employee ename="ana_sales">rd</employee> </Department> </Company> Part IV -- Swing (1 mark) 6 [1.0 marks] How can a GUI component handle its own events? A component can handle its own events by implementing the required eventlistener interface and adding itself as its own event listener. Page 8