Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013



Similar documents
CMSC 202H. ArrayList, Multidimensional Arrays

Software Development with UML and Java 2 SDJ I2, Spring 2010

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Sample CSE8A midterm Multiple Choice (circle one)

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

J a v a Quiz (Unit 3, Test 0 Practice)

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Introduction to Java

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Java Interview Questions and Answers

Contents. 9-1 Copyright (c) N. Afshartous

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Java Classes. GEEN163 Introduction to Computer Programming

Part I. Multiple Choice Questions (2 points each):

AP Computer Science Java Subset

Object-Oriented Programming in Java

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion

Lecture J - Exceptions

CS 111 Classes I 1. Software Organization View to this point:

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Basic Programming and PC Skills: Basic Programming and PC Skills:

CSE 8B Midterm Fall 2015

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

public static void main(string[] args) { System.out.println("hello, world"); } }

AP Computer Science Static Methods, Strings, User Input

Programming Languages CIS 443

C++ INTERVIEW QUESTIONS

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

COMPUTER SCIENCE. Paper 1 (THEORY)

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Building Java Programs

Building Java Programs

Chapter 1 Java Program Design and Development

Chapter 2 Introduction to Java programming

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Java Programming Language

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Conditionals (with solutions)

Introduction to Programming

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism

Java Application Developer Certificate Program Competencies

Introduction to Java Lecture Notes. Ryan Dougherty

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

WRITING DATA TO A BINARY FILE

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Moving from CS 61A Scheme to CS 61B Java

Java Basics: Data Types, Variables, and Loops

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Introduction to Object-Oriented Programming

Specialized Programme on Web Application Development using Open Source Tools

CS 106 Introduction to Computer Science I

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

Crash Course in Java

CS170 Lab 11 Abstract Data Types & Objects

Java CPD (I) Frans Coenen Department of Computer Science

Java SE 8 Programming

Java from a C perspective. Plan

Introduction to Java. CS 3: Computer Programming in Java

AP Computer Science Java Mr. Clausen Program 9A, 9B

Arrays. Introduction. Chapter 7

An Overview of Java. overview-1

Data Structures and Algorithms

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Chapter 5. Recursion. Data Structures and Algorithms in Java

Semantic Analysis: Types and Type Checking

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Tutorial on Writing Modular Programs in Scala

CS 1302 Ch 19, Binary I/O

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

JAVA - METHODS. Method definition consists of a method header and a method body. The same is shown below:

15-214: Principles of Software Construction 8 th March 2012

Continuous Integration Part 2

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

CmpSci 187: Programming with Data Structures Spring 2015

Yosemite National Park, California. CSE 114 Computer Science I Inheritance

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Variables, Constants, and Data Types

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris

TABLE OF CONTENTS...2 INTRODUCTION...3 APPLETS AND APPLICATIONS...3 JAVABEANS...4 EXCEPTION HANDLING...5 JAVA DATABASE CONNECTIVITY (JDBC)...

Collections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i),

Transcription:

Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper will have. Allocated time: 90 mins 18:15 19:45 Candidates should attempt ALL XX questions on the paper. You are advised to look through the questions before commencing your answers to assist in planning your strategy. Simplicity and clarity of expression in your answers is important. Electronic calculators are NOT allowed. This is a closed book test. You should not use a computer of any type to assist in answering the questions (this includes mobile devices of any type). Question: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Total Marks: 2 5 6 6 8 10 4 4 12 8 15 16 16 3 4 6 125 Answer the questions in the spaces provided on the question sheets. If you run out of room for an answer, continue on the back of the page. Name: User Id: OODP entry test Page 1 of 12 c Birkbeck 2013

Question 1...................................................................... 2 marks Write a switch statement to print the word even if the int variable number is even, or print the word odd if number is odd. Question 2...................................................................... 5 marks For each of the following in an Employee class, state whether it should be static, instance, or local. (a) An array of employees Social Security numbers. (b) Their job title. (c) A method to compute bonuses based on job titles. (d) A variable used to hold the number of hours they have worked this week. (e) A variable used to compute their additional pay for overtime work. Question 3...................................................................... 6 marks (a) (What is the purpose of the JDK? That is, what does having it allow you to do? 3 marks (b) What is the purpose of the JRE? That is, what does having it allow you to do? 3 marks OODP entry test Page 2 of 12 c Birkbeck 2013

Question 4...................................................................... 6 marks You can compute the average of two numbers by adding them together and dividing by two. (a) Write a method to compute and return the average of two double values. 2 marks (b) Should the above method be static? Why or why not? 2 marks (c) What will happen if you try to call the above method with two int values? 2 marks Question 5...................................................................... 8 marks Every Person must have a name. Every Employee (which extends Person) must have an integer employeeid. Write a minimal constructor for Employee utilising best practices for encapsulation. OODP entry test Page 3 of 12 c Birkbeck 2013

Question 6..................................................................... 10 marks Two Book objects are equal if they have the same ISBN, where isbn is an instance variable of type String. Write a correct and complete equals method for Book objects, and indicate (with a @ annotation) that it overrides the inherited equals method. Question 7...................................................................... 4 marks A class has a private instance int[] variable called position. Write a getter method for position. OODP entry test Page 4 of 12 c Birkbeck 2013

Question 8...................................................................... 4 marks (a) String s contains only digits. Write a single assignment statement to convert this string to an integer and assign it to variable n. 2 marks (b) Can you use the access modifiers public and private for variables declared inside a method? Why or why not? 2 marks Question 9..................................................................... 12 marks Consider the following code fragment. 1 ArrayList<String> list = new ArrayList<>(); 2 list.add("p"); 3 list.add("q"); 4 list.add("r"); 5 list.set(2,"s"); 6 list.add(2,"t"); 7 list.add("u"); 8 System.out.println(list); What is printed as a result of executing the code segment? [An extract from the API for the java.util.arraylist class is given at the end of the paper.] OODP entry test Page 5 of 12 c Birkbeck 2013

Question 10..................................................................... 8 marks List the four access modifiers available in Java and explain what each means for the instance variable or method that it modifies. OODP entry test Page 6 of 12 c Birkbeck 2013

Question 11.................................................................... 15 marks What is the output of the following Java program? 1 public class SuperWriter { 2 3 public SuperWriter(int n) { 4 for (int i = 0; i < n; i++) 5 System.out.print("N"); 6 } 7 8 public SuperWriter() { 9 System.out.print("W"); 10 } 11 12 public static void main(string[] args) { 13 System.out.println("String..."); 14 new Writer("ZYU"); 15 System.out.println(); 16 new SuperWriter(5); 17 System.out.println(); 18 } 19 20 } 21 22 class Writer extends SuperWriter { 23 public Writer(int num, boolean val, String s1, String s2) { 24 super(num - 1); 25 System.out.print(val? s1 : s2); 26 } 27 28 public Writer() { 29 System.out.print("I"); 30 } 31 32 public Writer(String name) { 33 System.out.println("A"); 34 System.out.println(name); 35 new Writer(); 36 new Writer(2, (1 > 3), "BB", "CD"); 37 } 38 39 } 40 OODP entry test Page 7 of 12 c Birkbeck 2013

Question 12.................................................................... 16 marks Write a recursive method that takes a string and produces the following output (this is for the string "abcde"). abcde abcd abc ab a ab abc abcd abcde OODP entry test Page 8 of 12 c Birkbeck 2013

Question 13.................................................................... 16 marks Due to fire restrictions only a certain number of people are allowed to be in a building at the same time. Write a class Bods that will not permit more than N instances of Bods to be constructed. If an attempt is made to construct more than N Bods, then an appropriate error message should be printed and the program exited. You should also include a howmanybods method that returns the number of Bods constructed so far. OODP entry test Page 9 of 12 c Birkbeck 2013

Question 14..................................................................... 3 marks Suppose you get a NullPointerException for the following statement: System.out.println(myFriend.spouse.getBirthday()); What can you say about the probable cause of the error? Question 15..................................................................... 4 marks For whom should you write internal (// and /*...*/) comments, and what kind of information should you convey? Question 16..................................................................... 6 marks Answer either part (a) or part (b), but NOT both. (a) Draw the memory diagram for the array that results from the following declaration: int[ ][ ] foo = new int[ ][ ] { { 3, 1, 4 }, {1, 5, 9 }, { 2, 6 } }; OODP entry test Page 10 of 12 c Birkbeck 2013

(b) What is printed by each of the following? i. System.out.print(1 + 2 + "buckle my shoe" + 3 + 4 + "close the door"); ii. System.out.print("hello".length() == 5? "yes" : "no"); iii. System.out.print(new char[] { a, b, c }); iv. int x; System.out.print(x = 5 + 7 * 2); v. char[] chs = new char[] { a, b, c }; System.out.print(chs[1]); OODP entry test Page 11 of 12 c Birkbeck 2013

Extract from the API for java.util.arraylist<e> ArrayList() boolean add(e elem) void add(int index, E element) Object set(int index, E element) E get(int index) E remove(int index) int size() Constructs an empty list with an initial capacity of ten. Appends the specified element to the end of this list and returns true. Inserts the specified element at the position index in this list. Replaces the element at position index with the specified element. Returns the element at the specified position in this list; throws an exception if the index is out of range. Removes the element at the specified position in this list and returns the element removed. Returns the number of elements in this list. OODP entry test Page 12 of 12 c Birkbeck 2013