Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Similar documents
Module Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 2

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2

Answer BOTH questions from Section A and ONE question from Section B.

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Module Contact: Dr Tony Bagnall, CMP Copyright of the University of East Anglia Version 1

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Exam Duration: 2hrs and 30min Software Design

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

JAVA MOCK TEST JAVA MOCK TEST III

Do not turn over until you are told to do so by the Invigilator.

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

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

Object Oriented Programming: Based on slides from Skrien Chapter 2

CGS 2405 Advanced Programming with C++ Course Justification

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Objects and Iterators

Sample Examination Paper Programming and Software Development

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

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Java Object Oriented Design. CSC207 Fall 2014

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

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

Lecture 15: Inheritance II

EECS2030 Week 7 worksheet Tue Feb 28, 2017

2. The object-oriented paradigm!

CS 251 Intermediate Programming Inheritance

CO Java SE 8: Fundamentals

UNIVERSITY OF SWAZILAND

Inheritance. COMP Week 12

CS111: PROGRAMMING LANGUAGE II

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

Practice for Chapter 11

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

25. Generic Programming

Inheritance and Polymorphism

Implements vs. Extends When Defining a Class

Final Examination Semester 3 / Year 2010

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

Java SE 8 Programming

Object Orientated Analysis and Design. Benjamin Kenwright

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

PROGRAMMING LANGUAGE 2

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

DATA STRUCTURES CHAPTER 1

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

CS313D: ADVANCED PROGRAMMING LANGUAGE

index.pdf January 21,

15CS45 : OBJECT ORIENTED CONCEPTS

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Inheritance, Polymorphism, and Interfaces

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

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

Type Hierarchy. Lecture 6: OOP, autumn 2003

Inheritance and Polymorphism

Chapter 5 Object-Oriented Programming

ITI Introduction to Computing II

Distributed Systems Recitation 1. Tamim Jabban

C12a: The Object Superclass and Selected Methods

OBJECT ORIENTED PROGRAMMING. Abstract Class And Interface

ITI Introduction to Computing II

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

Java Fundamentals (II)

UNIVERSITY OF EAST ANGLIA School of Computing Sciences May/June UG Examination EMBEDDED SYSTEMS CMPE3D02. Time allowed: 3 hours

Chapter 4 Defining Classes I

More about inheritance

Introduction to Inheritance

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


2. [20] Suppose we start declaring a Rectangle class as follows:

Chapter 7. Inheritance

TeenCoder : Java Programming (ISBN )

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:


Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

Computer Science II (20073) Week 1: Review and Inheritance

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Java SE 8 Programming

AP Computer Science A Course Syllabus

Module Contact: Dr Dan Smith, CMP Copyright of the University of East Anglia Version 1

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT. Object Oriented Programming

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. CMPUT 102: Inheritance Dr. Osmar R. Zaïane. University of Alberta 4

About this sample exam:

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. Inheritance Hierarchy. The Idea Behind Inheritance

CS111: PROGRAMMING LANGUAGE II

1.00 Lecture 13. Inheritance

Object-Oriented Design (OOD) and C++

Transcription:

UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2013-14 PROGRAMMING FOR NON-SPECIALISTS CMPC2X02 Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section B (Attempt one question: 40 marks) Notes are not permitted in this examination. Do not turn over until you are told to do so by the Invigilator. CMPC2X02 Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Page 2 1. (a) In the context of Java: SECTION A (i) distinguish between a class and an object; (ii) explain the differences between primitive data types and reference types; (iii) Distinguish between local variables and instance variables. (b) Explain what is meant by a static method in Java. Give a static method that takes a double representing a mass in pounds and returns a double representing the equivalent mass in kilograms. [If p is a mass in pounds, the equivalent mass in kilograms is given (approximately) by k = p 0.454.] [8 marks] 2. (a) In the following Java expressions, a, b, c and d are int variables. a * (9 - b) % c + d (c > 4) && (a <= 20) a!= (b + c) (i) Draw an evaluation tree for each of these expressions. [7 marks] (ii) Use these trees to evaluate each expression, assuming a has value 16, b has value 3, c has value 5 and d has value 2. (b) (i) Give a Java statement to define a constant identifier representing the number of hours worked in a normal working week (37.5 hours). (ii) Suppose workershours is an array of doubles whose elements represent the number of hours worked during a particular week. Write a fragment of Java code to determine the number of workers who worked overtime during that week.

Page 3 3. (a) Give the structure of a class defining a new type of object. [5 marks] (b) A class Car has the following fields: private String registration; private int doors; private String colour; private CarDealer supplier; (i) Define a class variable, totalcars, whose purpose is to keep track of the total number of Car objects constructed during execution of a program that uses the Car class. (ii) Define a constructor for this class which has a formal parameter corresponding to each field. (iii) Define an accessor method called getcolour whose purpose is to return the value of the colour field of the Car. (iv) Assume that the class CarDealer has a method with the header public Address getlocation() which returns the address of a CarDealer object. Define an accessor method for the class Car called getdealeraddress whose purpose is to return the address of the dealer who supplied this Car. (v) Assuming that an equals method is defined in the CarDealer class, define a method for the Car class that determines whether or not this Car has been supplied by a given CarDealer. TURN OVER

Page 4 4. (a) The Java standard library contains an interface called Comparable. Explain what is meant by the term interface in this context. (b) Explain what is meant by each of the following terms in the context of Java: (i) method overloading; (ii) method overriding; (c) Distinguish between an array and an ArrayList in Java. (d) (i) Give a Java statement to create an ArrayList called namelist to represent a list of workers names. (ii) Suppose newworker is the name of a new worker. Give a Java statement to insert this name at the end of namelist. (iii) Give an assignment statement assigning the number of workers in namelist to a variable workforcestrength.

Page 5 SECTION B 5. (a) Describe what is meant by each of the following terms in the context of Java programming: (i) inheritance; (ii) polymorphism; (iii) dynamic binding. (b) Assume that we have the following classes: Person, Administrator, Lecturer, Student, UnderGrad, PostGrad and Secretary. Administrator, Lecturer and Student are each subclasses of Person. PostGrad is a subclass of Student and Secretary is a subclass of Administrator. (i) Draw the inheritance hierarchy for the above classes. [7 marks] (ii) Which of the following assignments are legal and why? Person p1 = new Lecturer(); Person p2 = new Secretary(); Student s1 = new Person(); Student s2 = new PostGrad(); p1 = s2; [12 marks] (c) Write a brief explanation of each of the following kinds of error: (i) compile-time errors; (ii) run-time errors; (iii) logical errors. TURN OVER

Page 6 6. (a) A class LibraryBook has four fields: title, author, classification and status. The first three of these fields are of type String whilst status is of a user-defined type called BookStatus. At any time during its existence the status of a LibraryBook object is one of the following: reference only, on-loan or available for lending. (i) Define an enum type for a LibraryBook s status. (ii) Write a constructor for the LibraryBook class with explicit arguments to define the instance variables corresponding to the author and title fields. [5 marks] (iii) Write a method for the LibraryBook class to set the status of this LibraryBook to reference only, provided its status has not already been set. If the status of this LibraryBook has already been set an IllegalAttemptToSetStatusException should be thrown. (You may assume that the IllegalAttemptToSetStatusException class is available.) [7 marks] (iv) Write a boolean method for the LibraryBook class that returns true if the status of this LibraryBook is reference only, and false otherwise.

Page 7 (b) (i) Define what is meant by an algorithm. (ii) Describe the binary search algorithm for searching for a given value in a sorted array of values and state its worst-case run-time complexity. [10 marks] (iii) Show the working of your algorithm when it is used to search for 35 in the following array: a = [12,13,15,19,23,26,32,35,38,40,46,52]. END OF PAPER