UNIVERSITI TEKNOLOGI MALAYSIA FINAL EXAMINATION SEMESTER II, 2016 / 2017

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

Final Examination Semester 3 / Year 2008

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)

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

UNIVERSITI SAINS MALAYSIA. CIT502 Object-Oriented Programming and Software Engineering

Questions Answer Key Questions Answer Key Questions Answer Key

CSE 8B Final Exam Fall 2015

CISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE

CIS265 - Spring Exam 2 First Name Last Name CSU#

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

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

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

Fundamentals of Object Oriented Programming

CS159. Nathan Sprague

Lecture 18 CSE11 Fall 2013 Inheritance

JAVA GUI PROGRAMMING REVISION TOUR III

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

Programming - 2. Common Errors

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

Questions Answer Key Questions Answer Key Questions Answer Key

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

Exception-Handling Overview

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the

public UndergradStudent(String n, String m, String p) { programme = p; super(n, m);

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Inheritance and Polymorphism

Computer Programming, I. Laboratory Manual. Final Exam Solution

EXAMINATION FOR THE BSC (HONS) INFORMATION TECHNOLOGY; BSC (HONS) INFORMATION SYSTEMS & BSC (HONS) COMPUTER SCIENCE; YEAR 1

Class, Variable, Constructor, Object, Method Questions

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

SSE3052: Embedded Systems Practice

CS 113 PRACTICE FINAL

Review questions. Review questions, cont d. Class Definition. Methods. Class definition: methods. April 1,

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

Full file at Chapter 2 - Inheritance and Exception Handling

OOP in Java Review. CS356 Object-Oriented Design and Programming October 1, 2014

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

Final Examination Semester 3 / Year 2010

Lecture 7: Classes and Objects CS2301

EXAMINATION FOR THE DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 2

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

CS159. Nathan Sprague

Midterm Exam CS 251, Intermediate Programming October 8, 2014

The newest, most different stuff is Java variable declaration, array syntax, class instance syntax. Expect those to be emphasized.

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

CSCI 111 Midterm Spring 2014

OLLSCOIL NA héireann THE NATIONAL UNIVERSITY OF IRELAND COLÁISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK. Summer Examination 2012

Introduction to Computer Science II (CSI 1101)

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

Questions Answer Key Questions Answer Key Questions Answer Key

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Object- Oriented Analysis, Design and Programming

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

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

CS 11 java track: lecture 3

Inheritance (continued) Inheritance

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

Chapter 4 Defining Classes I

COMP 250: Java Object Oriented Programming

CMSC131. Exceptions and Exception Handling. When things go "wrong" in a program, what should happen.

What is Inheritance?

More on Objects in JAVA TM

Final Examination Semester 2 / Year 2011

COMP200 INTERFACES. OOP using Java, from slides by Shayan Javed

Final Examination Semester 3 / Year 2012

Final Examination Semester 2 / Year 2012

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

COE318 Lecture Notes Week 10 (Nov 7, 2011)

Introduction to Java. Handout-1d. cs402 - Spring

CS 116 Week 8 Page 1

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

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

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

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

COE318 Lecture Notes Week 8 (Oct 24, 2011)

Final Exam Practice. Partial credit will be awarded.

CSCI 261 Computer Science II

Exam Duration: 2hrs and 30min Software Design

Chapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved.

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

About This Lecture. Outline. Handling Unusual Situations. Reacting to errors. Exceptions

ITI Introduction to Computing II

Options for User Input

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

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

More on Exception Handling

16-Dec-10. Consider the following method:

CSCI 212 Practice Final Exam Summer Instructor: Krishna Mahavadi

Java for Non Majors Spring 2018

Anatomy of a Java Program: Comments

Exceptions, try - catch - finally, throws keyword. JAVA Standard Edition

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

CS 101 Exam 1 Spring 200 Id Name

6.Introducing Classes 9. Exceptions

Transcription:

SULIT Faculty of Computing SUBJECT CODE SUBJECT NAME YEAR/COURSE TIME DATE : VENUE : : SCSJ2154 : OBJECT ORIENTED PROGRAMMING : 2 (SCSJ / SCSV / SCSB / SCSR) : 1½ Hours INSTRUCTIONS : This test book consists of 2 parts: UNIVERSITI TEKNOLOGI MALAYSIA FINAL EXAMINATION SEMESTER II, 2016 / 2017 Part A: 10 Multiple Choice Questions 10 marks Part B: 4 Questions 40 marks ANSWER ALL QUESTIONS IN THE ANSWER BOOKLET. (Please Write Your Lecture Name And Section In Your Answer Booklet) Name I/C No. Year / Course Section Lecturer Name This questions paper consists of ELEVEN ( 11 ) printed pages excluding this page. 0

SECTION A: OBJECTIVE QUESTIONS (10 MARKS) Part A consists of 10 objective questions. Choose the best answer, and write your answer in the answer booklet. Each question carries 1 mark. 1. Object oriented inheritance models the A. "is a kind of" relationship B. "has a" relationship C. "want to be" relationship D. contains of relationship 2. What is the output of the following code? public class Test1 { public static void main(string[] args) { ChildClass c = new ChildClass(); c.print(); class ParentClass { int id = 1; void print() { System.out.println(id); class ChildClass extends ParentClass { int id = 2; A. 0 B. 1 C. 2 D. Nothing 3. Which of the following declares an abstract method in an abstract Java class? A. public abstract method(); B. public abstract void method(); C. public void abstract method(); D. public abstract void method() { 1

4. Which of the following statements is appropriate to be filled in the blank space in Program A1 below? //Program A1 public class TestBook1{ public static void main (String[] args){ LabBook book = new LabBook ("OOP",75.00); class Book{ private String title; public Book (String t){ title=t; System.out.println("Title : "+title); class LabBook extends Book { private double price; public LabBook (String t,double p){ System.out.println("Price : RM"+price); A. super(t); title=t; C. super(t); price=p; B. super(p); price=p; D. super(p); title=t; 5. Consider the following class definition: public class Student { protected int x; public abstract double print(); public void setx(int a) { x = a; public class Student() { x = 0; What is wrong with the class definition? A. The keywords public and abstract cannot be used together. B. The method print() in class Student must have a body. C. Class Student must be defined abstract. D. Variable x cannot be declared as protected. 2

6. Which of the following is a correct definition of interface class A? A. interface A { void print() { ; B. abstract interface A { print(); C. abstract interface A { abstract void print() { ; D. interface A { void print(); 7. Suppose A is an interface, B is a concrete class that implements A. Which of the following is correct? i. A a = new A(); ii. A a = new B(); iii. B b = new A(); iv. B b = new B(); A. i and ii only. B. ii and iv only. C. i and iii only. D. all above. 8. An instance of describes system errors. If this type of error occurs, there is little you can do beyond notifying the user and trying to terminate the program gracefully. A. RuntimeException C. Error B. Exception D. Throwable 3

9. What will happen when Program A2 is compiled and run? //Program A2 class Test { public static void main(string[] args) { try { String s = "10.5"; Integer.parseInt(s); int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); catch (Exception ex) { System.out.println(ex); i. An exception is raised due to Integer.parseInt(s); ii. iii. iv. An exception is raised due to 2/i; The program has a compilation error. The program compiles and runs without exceptions. A. i and ii only. B. ii only. C. iii only. D. iv only.. 10. What is wrong with the following program? //Program A3 class Test { public static void main (String[] args) { try { System.out.println("Welcome to Java"); A. You cannot have a try block without a catch block. B. You cannot have a try block without a finally block. C. A method call that does not declare exceptions cannot be placed inside a try block. D. Nothing is wrong. 4

SECTION B: STRUCTURED QUESTIONS (40 MARKS) Part B consists of 4 structured questions. Answer all questions in the answer booklet. The marks for each part of the question is as indicated. Question 1 [10 marks] Given the following Program B1; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 //Program B1 class ClassA{ public ClassA(){ public void method1() { System.out.println("UTM"); public void method1(string a) { System.out.println("UTM" +a); public void method1(int a) { System.out.println("UTM" +a); class ClassB extends ClassA{ public ClassB(){ public void method1() { System.out.println("FC UTM"); public void method1(string a) { System.out.println("FC UTM" +a); public void method2(string a, int b) { System.out.println("Studied at "+a+" in "+b); class ClassC extends ClassB{ public ClassC(){ public void method1() { System.out.println("SE@FC UTM"); public void method1(int a) { System.out.println(" SE@FC UTM" +a); public class TestFC { public static void main(string []args) { If the following statements are inserted at line 31 and 32, determine whether the program is correct or has an error during compilation. If the program is correct, state the output. If the program has an error, give the reason. Write your answer as in Table 1. a) ClassA ob = new ClassC(); ob.method1(2017); b) ClassA ob = new ClassC(); ob.method1("jb"); 5

c) ClassA ob = new ClassB(); ob.method2("fc UTM",2017); d) ClassC ob = new ClassB(); ob.method1(); e) ClassC ob = new ClassC(); ob.method2("fsksm UTM",1997); Statement No. a) b) c) d) e) Correct / Error Table 1 Output/Reason Question 2 [10 marks] Figure B1 shows relationship of the classes in Program B2. Write the missing Java statements in Program B2 as guided in the comment parts in order to implement the class hierarchy as in Figure B1. <<abstract>> Time + getminutes(): int Days - days: int + Days(int) HoursMinutes - hours: int - minutes: int + HoursMinutes(int, int) Figure B1 6

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. // Program B2 (i) // Declaration of abstract class Time { // [1 marks] (ii) // with an abstract method // getminutes() [1 marks] (iii) // Signature of class Days that { // inherits class Time [1 marks] private int days; (iv) // Parameterized constructor (v) // of class Days [2 marks] public int getminutes() { return days * 24 * 60; (vi) // Signature of class HoursMinutes that { // inherits class Time [1 marks] private int hours; private int minutes; (viii) // Parameterized constructor (ix) // of class HoursMinutes [2 marks] (x) public int getminutes() { return hours * 60 + minutes; public class Demo { public static void main(string args[]) { // Create an object of class Time that refer to class Days // named t1 with argument 2 (xi) // [1 marks] // Create an object of class Time that refer to class HoursMinutes // named t2 with arguments 4 and 10 (xii) // [1 marks] System.out.println(t1.getMinutes()); System.out.println(t2.getMinutes()); 7

Question 3 [10 marks] Given the UML class diagram in Figure B2, Program B3, and output in Figure B3, answer the following questions (a) to (c). <<interface>> GST GSTRate = 0.06: double + getgstcharges(): double + calcgst(); void <<interface>> Discount discountrate = 0.05: double + getdiscount(): double + calcdiscount(): double Book BookApplication price : double + Book(double) + tostring(): String + main(string []): void Figure B2: The UML class diagram Figure B3 : Output of Program B3 8

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 //Program B3 (a) { { (b) { public String tostring(){ return "\ninitial Price: "+price+"\nprice after 5% discount: "+ (price-calcdiscount())+ "\nprice after discount and GST: "+(price-calcdiscount()+getgstcharges()); public double getgstcharges() {return price*rate; public double calcgst() {return price+getgstcharges(); public double getdiscount() { return rate; public double calcdiscount() { return price*getdiscount(); public class BookApplication { public static void main(string[] args) { (c) (d) a) Write Java code that defines GST (line 3-7) and Discount (line 11-15) interface classes [5 marks] b) Write Java code that defines class Book (line 18-22) that implements the interfaces defined in (a). [3 marks] c) Write Java code to create a Book object with price is initialized with 10. [ 1 mark] d) Display the price of book after discounts and tax levied GST by invoking tostring() method. [1 mark] 9

Question 4 [10 marks] a. Answer question (i) to (v) as in Program B4 below with suitable codes so that it can throw the exception. [ 5 marks] //Program B4 public class FinalExamException { public static void main (String args[]) { int arr []={30,40; Scanner in= new Scanner (System.in); (i) { int b = in.nextint(); int x = arr[2]/ (b arr[1]); catch ( (ii) ex) { System.out.println("Exceed array size ); catch ( (iii) ex) { System.out.println("Denominator is zero ); catch ( (iv) ex) { System.out.println("Invalid data: +e); (v) { int y = arr[1]/ arr[0]; System.out.println("y = +y); 10

b. Given Program B5 below, answer the following question. i. Explain why error will occur when Program B5 is compiled? [ 2 marks] ii. Rewrite the program so that the program will compile and run properly. [ 3 marks] //Program B5 class Test { public static void main(string[] args) { try { String s = "5.6"; Integer.parseInt(s); int i = 0; int y = 2 / i; catch (Exception ex) { System.out.println("NumberFormatException"); catch (RuntimeException ex) { System.out.println("RuntimeException"); 11