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

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

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

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

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

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

University of Palestine. Mid Exam Total Grade: 100

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

Exam Duration: 2hrs and 30min Software Design

Computer Programming, I. Laboratory Manual. Final Exam Solution

Introduction to Programming Using Java (98-388)

CMSC 331 Second Midterm Exam

Problem Grade Total

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

CS 113 PRACTICE FINAL

Tutorial 8 Date: 15/04/2014

Faculty of Science FINAL EXAMINATION

CS 101 Fall 2005 Midterm 2 Name: ID:

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

JAVA Programming Language Homework II Student ID: Name:

Java Identifiers, Data Types & Variables

CS 101 Spring 2006 Final Exam Name: ID:

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

Final Exam. COMP Summer I June 26, points

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

PROGRAMMING FUNDAMENTALS

1. An operation in which an overall value is computed incrementally, often using a loop.

NATIONAL UNIVERSITY OF SINGAPORE

Selected Questions from by Nageshwara Rao

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

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

Largest Online Community of VU Students

Introduction to Java

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Midterm Exam CS 251, Intermediate Programming March 12, 2014

3. Java - Language Constructs I

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)

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

Computer Science 1 Ah

Java and OOP. Part 2 Classes and objects

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

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

CS 112 Final May 8, 2008 (Lightly edited for 2012 Practice) Name: BU ID: Instructions

Sample Examination Paper Programming and Software Development

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

About this exam review

Data Structure (CS301)

Points off Total off Net Score. CS 314 Final Exam Spring 2016

COS 126 General Computer Science Spring Written Exam 1

COMP 250 Midterm #2 March 11 th 2013

Inheritance and Interfaces

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

Midterm Exam CS 251, Intermediate Programming October 8, 2014

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

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

Faculty of Science COMP-202A - Foundations of Computing (Fall 2012) - All Sections Midterm Examination

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

COS 126 Midterm 1 Written Exam Fall 2012

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

JAVA OPERATORS GENERAL

CIS 110 Introduction to Computer Programming. 17 December 2012 Final Exam

CSC 1214: Object-Oriented Programming

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

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

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

Java Application Development

Advanced Java Concepts Unit 3: Stacks and Queues

CIS 110 Introduction to Computer Programming. 13 February 2013 Make-Up Midterm Midterm

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

ECE Fall 20l2, Second Exam

1 Method Signatures and Overloading (3 minutes, 2 points)

SAMPLE EXAM Second Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 11 November 2010

(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

COM S 211/ENGRD 211 May 15, 2003

In addition to the correct answer, you MUST show all your work in order to receive full credit.

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

Computational Expression

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

Accurate study guides, High passing rate! Testhorse provides update free of charge in one year!

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

Lec 3. Compilers, Debugging, Hello World, and Variables

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

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

COP 3330 Final Exam Review

Final CSE 131B Spring 2004

CSE351 Winter 2016, Final Examination March 16, 2016

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

Solutions to the 2005 exam

CSCE145 Test 2-Review 03/29/2015 Hongkai Yu

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

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

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

Midterm Exam CS 251, Intermediate Programming March 6, 2015

CS260 Intro to Java & Android 03.Java Language Basics

Variables and Java vs C++

CSE373 Fall 2013, Midterm Examination October 18, 2013

RAIK 183H Examination 2 Solution. November 10, 2014

Transcription:

Object Oriented Programming 2014/15 Final Exam July 3, 2015 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 Version A Page 1

Part I -- UML (1.5 marks) 1 Consider an Emergency Room (ER) of a Hospital. It is organized in several sections. There are observation sections (where patients are observed) and surgery sections (where patients undergo a surgery). Each observation section has a number of beds. Surgery sections have one or two surgery rooms. Each surgery room has one or two beds. Each section maintains a list of the staff on duty; staff members are identified by their name and id number. The staff member positions are: Auxiliary, Doctors and Nurses. Doctors and Nurses are also identified by they medical subspecialty; in addition Doctors also have their prescriber ID. When patients arrive to the ER they are placed in a queue for triage. After triage patients go directly to a section queue. If a bed is available, the patient is removed from the queue and assigned to the free bed. 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 one observation section with two beds, a doctor and a nurse, with one patient waiting in the section queue. Set all needed attributes/associations with some dummy values. Part II -- Java (6.5 marks) 2 A ternary min-heap is an ordered tree-based data structure with the following properties: (i) every node has a value; (ii) every node s value is less than all the values in the descendent nodes; (iii) all nodes have at most three descendants (left, middle, and right sub-heaps) that also fulfill the heap conditions. Provide an implementation of a ternary min-heap, named TriHeap. Usually heaps are implemented taking profit of arrays; here, for the sake of simplicity, implement it as a tree-based data structure. The TriHeap class should be generic with type parameter V (for the value). In addition, the type parameter V must implement the Comparable interface. The Comparable is the only type you can use from java.util package. a) [0.5 marks] Provide the skeleton of the necessary classes with fields and constructors. For the TriHeap class only a no-arg constructor is needed. b) [1.0 marks] Provide an insert method that receives a value of type V and inserts the value in the heap; it returns void. If the value being inserted already exists in the heap then the new value is not inserted. When the value is placed in a node it must preserve the heap structure. In addition, the depth of the sub-heaps should be balanced, as much as possible. c) [0.5 marks] Provide a depth method that returns the depth of the heap (the length of the largest branch). d) [0.5 marks] Provide a delete method that receives a value of type V and removes from the heap that value. e) [0.5 marks] Provide a search method receives a value of type V and returns true if the value belongs to the heap and false otherwise. Note that the heap structure should be taken into account to optimize the method. Page 3

public class TriHeap<V extends Comparable<V>> { Node<V> root; public TriHeap() { /* INSERT: */ public void insert(v value){ if (root==null) root=new Node<V>(value); else { V aux; if (root.value.compareto(value)>0){ aux = root.value; root.value=value; else aux = value; int lnbnodes=root.left.nbnodes(), mnbnodes=root.middle.nbnodes(), rnbnodes=root.right.nbnodes(); if (lnbnodes<=rnbnodes && lnbnodes<=mnbnodes) root.left.insert(aux); else if (mnbnodes<=rnbnodes) root.middle.insert(aux); else root.right.insert(aux); private int nbnodes(){ if (root==null) return 0; return 1+root.left.nbNodes()+root.middle.nbNodes()+root.right.nbNodes(); /* DEPTH: */ public int depth(){ if (root==null) return 0; int ldepth=root.left.depth(); int mdepth=root.middle.depth(); int rdepth=root.right.depth(); return (ldepth>mdepth && ldepth>rdepth? ldepth+1 : mdepth>rdepth? mdepth+1 : rdepth+1); /* DELETE: delete need not to produce a balanced tree! */ public void delete(v value){ if (root==null) return; if (root.value.equals(value)){ if (depth()==1) root=null; else { TriHeap<V> lth=root.left, mth=root.middle, rth=root.right; root=null; join(lth); join(mth); join(rth); else if (root.value.compareto(value)<0) { root.left.delete(value); root.middle.delete(value); root.right.delete(value); private void join(triheap<v> th){ Page 4

private void join(triheap<v> th){ if (th.root==null) return; insert(th.root.value); join(th.root.left); join(th.root.middle); join(th.root.right); /* SEARCH: */ public boolean search(v value){ if (root==null) return false; if (root.value.equals(value)) return true; if (root.value.compareto(value)>0) return false; return root.left.search(value) root.middle.search(value) root.right.search(value); public class Node<V extends Comparable<V>> { TriHeap<V> left; TriHeap<V> middle; TriHeap<V> right; V value; public Node(V v) { value=v; left=new TriHeap<V>(); middle=new TriHeap<V>(); right=new TriHeap<V>(); 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 C A C E D a) [0.5 marks] What is the value of the class field x after building two objects of type X with the no-arg constructor? class X { static int x=0; static { x+=1; int y=-1; { y+=2; public X() { this(2); public X(int y) { x=x+y; A. 3 B. 4 C. 5 D. 6 E. The code does not compile b) [0.5 marks] Consider the following classes and identify, method by method of class Y, which are overload, override or compile-time errors. The methods are ordered in the alternatives (A, B, C, D and E) as q;r;v;t. class X { class Y extends X { int q(){ long q(){ Number r(int x) { Long r(int y) { Integer v() { <T extends Number> T v(){ <T extends Number> T t(){ Integer t() { A. compile-time error; override; compile-time error; override B. override; override; override; override C. override; override; overload; overload D. compile-time error; override; overload; override E. compile-time error; override; overload; overload c) [0.5 marks] What is the size of a long variable in Java? A. 2 bytes B. 4 bytes C. 8 bytes D. It depends on the compiler settings E. It depends on the operating system Page 6

d) [0.5 marks] What is printed to the terminal? A. class X{ B. A. 5 20 10 B. 10 15 10 C. 5 15 5 D. 10 20 10 E. 5 20 5 private int xpto(){return 5; public static int foo() {return 15; public static void main(string[] args){ X x = new Y(); Y y = (Y)x; System.out.print(x.xpto()); System.out.print(y.foo()); System.out.print(((X)y).xpto()); class Y extends X{ public int xpto(){return 10; public static int foo() {return 20; e) [0.5 marks] What is the output of the following code (if any)? A. Finished B. Exception C. Arithmethic Exception D. None, compilation fails E. Nothing is printed try { int x = 0; int y = 5 / x; catch (Exception e) { System.out.println("Exception"); catch (ArithmeticException ae) { System.out.println(" Arithmetic Exception"); System.out.println("Finished"); 4 [1.0 marks] Explain the open-closed principle of OOP. In OOP, the open-closed principle states that software entities (classes, interfaces, etc.) should be open for extension, but closed for modification. Page 7

Part III -- XML (1 mark) 5 [1.0 marks] Consider the problem presented in Part I and, particularly, problem 1b), that is, consider one observation section with two beds, a doctor and a nurse, with one patient waiting in the section queue. Informally, present an XML document, with XML elements and attributes, to store all information needed, as well as the corresponding DTD. 6 [1.0 marks] What is a layout manager? Part IV -- Swing (1 mark) A layout manager is an object that implements the LayoutManager interface; it determines the size and position of the components within a container. Page 8