FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 07/2014 SESSION 8:00-10:00

Similar documents
FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 09/06/2014 SESSION 8:30-10:30

1. Write a program to calculate distance traveled by light

Information System Desig

ITI Introduction to Computing II

COMPUTER SCIENCE TRIPOS

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

Physics 121, Midterm Exam #3 Tuesday April 20, am 9.30 am. Do not turn the pages of the exam until you are instructed to do so.

UML. Design Principles.

Data Structures and Algorithms Winter Semester

Techniques of Java Programming

Course Announcements. Bacon is due next Monday. Next lab is about drawing UIs. Today s lecture will help thinking about your DB interface.

Computer Science Introductory Course MSc - Introduction to Java

Name: Student ID: Instructions:

Scripting Languages Fast development, extensible programs

Multimedia Interactive Simulations of Physical Experiments

ITI Introduction to Computing II

UNIVERSITY OF WISCONSIN MADISON

Extensibility Patterns: Extension Access

Course Announcements. John Jannotti (cs32) Scope, Collections & Generics Feb 8, / 1

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculty of Mathematics and Computer Science Exam Cryptology, Tuesday 30 October 2018

Combinational Digital Design. Laboratory Manual. Experiment #6. Simplification using Karnaugh Map

Introduction to Computing II (ITI1121) FINAL EXAMINATION

A GUI FOR EVOLVE ZAMS

An object-oriented design process. Weather system description. Layered architecture. Process stages. System context and models of use

Checkpoint Questions Due Monday, October 1 at 2:15 PM Remaining Questions Due Friday, October 5 at 2:15 PM

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 1 Discussion:

Computation Theory Finite Automata

1 Java Night Countdown (30%)

NAME... Soc. Sec. #... Remote Location... (if on campus write campus) FINAL EXAM EE568 KUMAR. Sp ' 00

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University

Geometry EOC Item Specifications Florida Standards Assessments. Equation Editor. 15 P a g e M a r c h 2 4,

Algorithms and Programming I. Lecture#1 Spring 2015

Read this before starting!

Physics 218 Exam I. Fall 2018 (all UP sections) September 26 th, 2018

California State University Northridge MATH 280: Applied Differential Equations Midterm Exam 1

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

AS Mathematics Assignment 8 Due Date: Friday 15 th February 2013

Learning outcomes. Palettes and GIF. The colour palette. Using the colour palette The GIF file. CSM25 Secure Information Hiding

Quantum parity algorithms as oracle calls, and application in Grover Database search

California State University Northridge MATH 280: Applied Differential Equations Midterm Exam 3

AJJAR Astronomical Javascript/Java Applet Resource

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;

Read this before starting!

SUPPLEMENTARY INFORMATION

Project 2: Hadoop PageRank Cloud Computing Spring 2017

1 SIMPLE PENDULUM 1 L (1.1)

Design and implementation of a new meteorology geographic information system

COURSE CONTENT for Computer Science & Engineering [CSE]

Algorithmic verification

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20

INF Models of concurrency

MAT300/500 Programming Project Spring 2019

CSE370: Introduction to Digital Design

Lisp Introduction. Dr. Neil T. Dantam. Spring CSCI-498/598 RPM, Colorado School of Mines. Dantam (Mines CSCI, RPM) Lisp Spring / 88

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

Conformational Analysis of n-butane

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019

CMSC 330: Organization of Programming Languages

Written Exam Linear and Integer Programming (DM554)

Rolling marble lab. B. Pre-Lab Questions a) When an object is moving down a ramp, is its speed increasing, decreasing, or staying the same?

Successful completion of the core function transformations unit. Algebra manipulation skills with squares and square roots.

Written Exam Linear and Integer Programming (DM545)

1. Introduction. Hang Qian 1 Iowa State University

CS Exam 1 Study Guide and Practice Exam

Recitation Session: CHS PRINCIPLES OF CHEMISTRY:- T - 12:30PM - 1:20PM - CB1 105

MAT2345 Discrete Math

Outline. policies for the first part. with some potential answers... MCS 260 Lecture 10.0 Introduction to Computer Science Jan Verschelde, 9 July 2014

Name: Math 1120, Final. December 12, Net id: PLACE AN X IN THE BOX TO INDICATE YOUR SECTION

Date: Summer Stem Section:

Environmental Systems Research Institute

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

More on Methods and Encapsulation

Laboratory 4: Wave Motion and Resonance

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10

Using web-based Java pplane applet to graph solutions of systems of differential equations

Implementation of CCSDS Recommended Standard for Image DC Compression

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015

Clojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014

Pre-AP Algebra 2 Unit 8 - Lesson 5 Functions that differ at only one point; holes; simplifying rational functions

Java Programming. Final Examination on December 13, 2015 Fall 2015

CS Data Structures and Algorithm Analysis

GIS Software. Evolution of GIS Software

Using Easy Java Simulations in Computer Supported Control Engineering Education

1 SIMPLE PENDULUM 1 L (1.1)

Part I : Multiple Choice.

COMPUTER SCIENCE TRIPOS

Read this before starting!

Tabulation means putting data into tables. A table is a matrix of data in rows and columns, with the rows and the columns having titles.

Read this before starting!

CityGML XFM Application Template Documentation. Bentley Map V8i (SELECTseries 2)

PHYS 124 Section A1 Mid-Term Examination Spring 2006 SOLUTIONS

Name: Student ID number:

Outline Oxana Smirnova, Particle Physics 2

GIS for spatial decision making

Distance From the Sun

CS 2110: INDUCTION DISCUSSION TOPICS

Three-Dimensional Visualization of Activity-Travel Patterns

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING COMPUTER SCIENCES DEPARTMENT UNIVERSITY OF WISCONSIN-MADISON

Voortgezet Programmeren

Transcription:

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING MODULE CAMPUS CSC2A10 OBJECT ORIENTED PROGRAMMING AUCKLAND PARK CAMPUS (APK) EXAM JULY 2014 DATE 07/2014 SESSION 8:00-10:00 ASSESOR(S) INTERNAL MODERATOR MR DT VAN DER HAAR MR A MAGANLAL DR ID ELLEFSEN DURATION 2 HOURS MARKS 100 NUMBER OF PAGES: 6 PAGES INSTRUCTIONS: ANSWER ALL THE QUESTIONS REQUIREMENTS: AN EXAM BOOK FOR THE STUDENT 1

SECTION A - Theory QUESTION 1 Java Basics (a) List 4 design goals of the Java language. (b) You have been approached by an embedded systems engineer with extensive C++ experience. Discuss the differences between Java and C++ with respect to pointers, primitive data types, exception handling and multi-threading. (c) Briefly describe what is a JVM. QUESTION 2 (a) What are data storage sizes (in bits) for the following data types: 1. int 2. short 3. Object Reference 4. byte (b) Name 4 logical operators that can be used in a selection statement. (c) Provide a short Java source code example that demonstrates flow control. QUESTION 3 Elementary Java Programming (a) Explain why method overriding is useful for developers. (b) The following Java code segment is for a method that intends to modify a class data [3] member. Does the method achieve this task? Provide a reason for your answer. 1 c l a s s Student { 2 p r i v a t e S t r i n g name ; 3 p u b l i c void setname ( S t r i n g name ) 4 { 5 name = name ; 6 } 7 } (c) Classify the Selection Sort algorithm in terms of: [3] Computational complexity Memory usage for N elements Iterative versus recursive approach 2

QUESTION 4 Text Processing and Persistence (a) Briefly describe why Strings are said to be immutable in Java. (b) What Java classes will be required for reading the first line of a text file? (c) Provide a regular expression that provides the following match result (you do not have to provide Java source code): QUESTION 5 Object Orientation (a) Analyse the Java source code below. Are there any problems that occur? Provide a [3] reason for you answer. 1 i n t e r f a c e D i s p l a y a b l e { 2 p u b l i c void d i s p l a y ( S t r i n g message ) ; 3 } 4 5 c l a s s M e s s a g e P r o v i d e r implements D i s p l a y a b l e { 6 p u b l i c void d i s p l a y ( S t r i n g message ) { 7 System. out. p r i n t l n ( message ) ; 8 } 9 } 10 11 c l a s s Main{ 12 p u b l i c s t a t i c void main ( S t r i n g [ ] a r g s ) { 13 D i s p l a y a b l e m = new M e s s a g e P r o v i d e r ( ) ; 14 m. d i s p l a y ( Test ) ; 15 } 16 } (b) Aside from general aggregation, list 3 other types of relationships that can be used when [3] modelling UML class diagrams. (c) List 2 properties of an interface. QUESTION 6 Graphical User Interfaces (a) Aside from AWT what other graphical user interface framework is provided by Java? Provide 2 properties for this GUI framework. 3

(b) Discuss how event handling is achieved in Java. Be sure to include all the components that are required. QUESTION 7 Advanced Java Programming (a) Provide HTML that can be used to embed an applet (VideoPlayer.class of size 640 by 480) into a basic web page. (b) Discuss how exception handling is achieved in Java. You provide Java source code to illustrate your answer. QUESTION 8 Design Patterns (a) Provide a UML class diagram that illustrates the Proxy design pattern. (b) Aside from the proxy design pattern, name 3 other design patterns, along with their [6] limitations. SECTION B - Practical QUESTION 9 Provide Java source code for a paintcomponent function which will draw a green circle of radius 50. QUESTION 10 Provide Java source code for a function to write a binary file called code.bin. The following data must be written to file: The current year (2014) The string Total The number 28 The number 5 Remember to include any necessary exception handling. packages have been imported. You can assume that all necessary 4

QUESTION 11 Read the code below and provide the missing code (in the segments labelled as A to G). 1 import j a v a. u t i l. A r r a y L i s t ; 2 import j a v a. u t i l. Random ; 3 4 c l a s s C o n t e s t a n t implements (A (2 marks ) ) 5 { 6 p r i v a t e f i n a l Random randgen ; 7 p r i v a t e f i n a l S t r i n g name ; 8 p r i v a t e i n t answer, time ; 9 10 p u b l i c C o n t e s t a n t ( S t r i n g name ) 11 { 12 t h i s. name = name ; 13 randgen = new Random ( name. hashcode ( ) ) ; 14 } 15 16 @Override 17 p u b l i c void (B (1 marks ) ) 18 { 19 20 time = ( randgen. n e x t I n t ( 3 0 ) +1) 1 0 ; 21 t r y 22 { 23 // S i m u l a t e t h i n k i n g time 24 (C (2 marks ) ). s l e e p ( time ) ; 25 } 26 catch ( (D (2 marks ) ) e ) 27 { 28 e. p r i n t S t a c k T r a c e ( ) ; 29 } 30 answer = randgen. n e x t I n t (100) ; 31 System. out. format ( %s g u e s s e d %d\ t%d%n, getname ( ), getanswer ( ), gettime ( ) ) ; 32 } 33 34 p u b l i c S t r i n g getname ( ) 35 { 36 r e t u r n name ; 37 } 38 39 p u b l i c i n t getanswer ( ) 40 { 41 r e t u r n answer ; 42 } 43 44 p u b l i c i n t gettime ( ) 45 { 46 r e t u r n time ; 47 } 48 49 } 50 51 p u b l i c c l a s s GameShow 52 { 53 54 p u b l i c s t a t i c void main ( S t r i n g [ ] a r g s ) 55 { 56 i n t answer = new Random ( ). n e x t I n t (100) ; 57 58 A r r a y L i s t < (E (1 marks ) ) > c o n t e s t a n t s = new A r r a y L i s t <>() ; 5

59 c o n t e s t a n t s. add (new C o n t e s t a n t ( Bob ) ) ; 60 c o n t e s t a n t s. add (new C o n t e s t a n t ( S a l l y ) ) ; 61 c o n t e s t a n t s. add (new C o n t e s t a n t ( Thabo ) ) ; 62 c o n t e s t a n t s. add (new C o n t e s t a n t ( Mpho ) ) ; 63 c o n t e s t a n t s. add (new C o n t e s t a n t ( R a j e s h ) ) ; 64 65 C o n t e s t a n t w i n n e r = n u l l ; 66 A r r a y L i s t <Thread> t h r e a d s = new A r r a y L i s t <Thread >() ; 67 System. out. p r i n t l n ( The answer i s + answer ) ; 68 w h i l e ( w i n n e r == n u l l ) 69 { 70 71 f o r ( C o n t e s t a n t c o n t e s t a n t : c o n t e s t a n t s ) 72 { 73 Thread thd = new Thread ( c o n t e s t a n t ) ; 74 t h r e a d s. add ( thd ) ; 75 (F (1 marks ) ). s t a r t ( ) ; 76 } 77 f o r ( Thread thd : t h r e a d s ) 78 { 79 t r y 80 { 81 thd. j o i n ( ) ; 82 } 83 catch ( I n t e r r u p t e d E x c e p t i o n e ) 84 { 85 e. p r i n t S t a c k T r a c e ( ) ; 86 } 87 } 88 System. out. p r i n t l n ( Checking g u e s s e s ) ; 89 f o r ( C o n t e s t a n t c o n t e s t a n t : c o n t e s t a n t s ) 90 { 91 92 i f ( w i n n e r == n u l l && (G (1 marks ) ) == answer ) 93 { 94 w i n n e r = c o n t e s t a n t ; 95 } 96 } 97 t h r e a d s. c l e a r ( ) ; 98 } 99 System. out. p r i n t l n ( The w i n n e r i s \ t + w i n n e r. getname ( ) ) ; 100 101 } 102 103 } The End! 6