The Islamic University Gaza Department of Electrical & Computer Engineering. Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324

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

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

Midterm assessment - MAKEUP Fall 2010

Inheritance and Polymorphism

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

Java for Non Majors Spring 2018

AP CS Unit 6: Inheritance Notes

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

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

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

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

Practice for Chapter 11

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

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

Overriding Variables: Shadowing

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

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Final Examination Semester 3 / Year 2008

Inheritance. Transitivity

Class, Variable, Constructor, Object, Method Questions

CSCI 201L Written Exam #1 Fall % of course grade

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

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

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

Java Programming Lecture 6

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

CS 112 Introduction to Programming. (Spring 2012)

Computer Programming, I. Laboratory Manual. Final Exam Solution

CS1150 Principles of Computer Science Objects and Classes

Tutorial 8 Date: 15/04/2014

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

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

Java Object Oriented Design. CSC207 Fall 2014

CSCI 201L Written Exam #1 - SOLUTION Fall % of course grade

Full file at Chapter 2 - Inheritance and Exception Handling

OVERRIDING. 7/11/2015 Budditha Hettige 82

Abstract class & Interface

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

DM503 Programming B. Peter Schneider-Kamp.

CSCI 201L Midterm Programming. Fall % of course grade

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

CISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions

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

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

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.

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

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

CMP-326 Exam 2 Spring 2018 Total 120 Points Version 1

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

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Laying Out Components. What is Widget Layout?

COE318 Lecture Notes Week 10 (Nov 7, 2011)

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

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Object-Oriented Concepts

Inheritance and Polymorphism

15CS45 : OBJECT ORIENTED CONCEPTS

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

C# Programming for Developers Course Labs Contents

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

Final Examination Semester 2 / Year 2010

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

Lecture 2: Java & Javadoc

Inheritance and Polymorphism. CS180 Fall 2007

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

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


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

First IS-A Relationship: Inheritance

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

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

CS 180 Fall 2006 Exam II

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

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

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College

University of Cape Town Department of Computer Science Computer Science CSC1017F

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

CS 11 java track: lecture 3

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School

Chapter 13 Lab Advanced GUI Applications

Mobile Application Development ( IT 100 ) Assignment - I

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

Name:... ID:... class A { public A() { System.out.println( "The default constructor of A is invoked"); } }

Fundamentals of Object Oriented Programming

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.

Questions Answer Key Questions Answer Key Questions Answer Key

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

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

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

Java Magistère BFA

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.

COP 3330 Final Exam Review

Object Oriented Programming. Java-Lecture 11 Polymorphism

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

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

Transcription:

The Islamic University Gaza Department of Electrical & Computer Engineering Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324 Instructor: Dipl.-Ing. Abdelnasser Abdelhadi Date: 31.03.2013 / Duration: 1.5 hours Name SID Max Mark Mark 30 Question 1 Determine whether the following statements are true or false? 1. An abstract class can be extended (F) 2. A subclass of a non-abstract superclass can be abstract (T) 3. If a class contains a single abstract method, it must be abstract. (T) 4. Polymorphism means that a variable of superclass can refer to a subtype object. (T) 5. A class can implement many interfaces. (T) 6. a subclass can override a private method declared in superclass (F) 7. Variables declared in interfaces are implicitly public, static, and final. (T) 8. All methods in an Interface are always private and abstract by default. (F) 9. a method can overridden in the same class (F) 10. An interface can extend many interfaces. (T) page 1/5

Question 2 Given is the following code. public class Division { public static void main(string[] args) { Block1: for (int i = 2; i >= -3; i--) { try { double z = division(5, i); System.out.println("Result: " + z); catch(arithmeticexception ar){ System.out.println(ar.getMessage()); break; Block2: catch (Exception ex) { System.out.println(ex.getMessage()); finally{ System.out.println("i: "+i); System.out.println("Finish"); public static double division(double x, double y) throws Exception{ if(y==0) { throw new ArithmeticException("Cann`t divid number by zero!"); else if(y==1) { throw new Exception("division by 1 is forbidden."); else{ return x/y; a. What is the output? Result: 2.5 i: 2 division by 1 is forbidden. i: 1 Cann`t divid number by zero! i: 0 Finish b. How would the exchanging of Block1 and Block2 affect the program? (explain your answer) It case an compilation error, because we can t handle the specific exception (ArithmeticException) after the general exception (Exception) Since all ArithmeticException is an Exception so it will handled by block 1 and block2 become unreachable code. page 2/5

Question 3 Given is the following program: public interface Animal { int numberoflegs(); boolean ispredator(); public abstract class Mammal implements Animal{ public int id; public Mammal(int id) { this.id = id; public int numberoflegs() { return 4; return "Is preditor: " + ispredator() ; public class Sheep extends Mammal{ public Sheep(int id) { super(id); public boolean ispredator() { return false; return "This Sheep " + super.tostring(); public class Shark implements Animal{ public boolean ispredator() { return true; public int numberoflegs() { return 0; return "Shark predator: "+ispredator(); page 3/5

public class Tester { public static void main(string[] args) {; 1. display(new Sheep(1)); 2. display(new Shark()); static void display(animal m){ 3. System.out.println(m.toString()); 1. Complete the missing methods or constructor in the upper classes. Shark is predator and has 0 legs. Sheep is not predator and has 4 legs. The Shark object tostring() return Shark predator: true,legs: 0. 2. Complete the parameter list of the method display so that the invoking in line 1 and 2 compile correctly. 3. Is a Sheep object instance of Mammal? Yes 4. Is a Sheep object instance of Animal? Yes 5. What do we call the repeating of the method tostring () in Mammal and Sheep? Overriding 6. What do we call the using of super class and subclass objects in line 1 and 2 to invoke the method display? Polymorphism 7. What is the output of the program after completion your code? Shark predator: true,legs: 0 This Sheep Is preditor: false,legs: 4 page 4/5

Question 4 Complete the program as following: 1. Your code produce the showing Jfram 2. Set the frame title to Midterm Frame. 3. Set the frame size to 220 x 300. 4. The spaces between buttons 1-6 is 2. 5. The spaces between buttons 1-6 and East Button is 5. 6. South button has: Gray background. Times New Roman bold font with size 12. Helping keywords: BorderLayout, FlowLayout, GridLayout BorderLayout.CENTER, BorderLayout. EAST, BorderLayout. WEST, BorderLayout. SOUTH Font.BOLD, Color.gray public class ExamGUI extends JFrame{ public ExamGUI(String title) { super(title); JPanel p = new JPanel(new GridLayout(3, 2,2,2)); for(int i=1;i<=6;i++){ p.add(new JButton(""+i)); setlayout(new BorderLayout(5, 5)); add(p,borderlayout.center); JButton jb = new JButton("South"); jb.setbackground(color.gray); jb.setfont(new Font("Times New Roman", Font.BOLD, 12)); add(jb,borderlayout.south); add(new JButton("East"),BorderLayout.EAST); public static void main(string[] args) { ExamGUI gui = new ExamGUI("Mid Term"); gui.setdefaultcloseoperation(exit_on_close); gui.setlocationrelativeto(null); gui.setsize(220, 300); gui.setvisible(true); page 5/5