Model answers/marking scheme in bold, additional comments in bold italic.

Similar documents
COMP19612 exam performance feedback 2014

A4 Explain how the Visitor design pattern works (4 marks)

Exam Duration: 2hrs and 30min Software Design

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO

Logistics. Final Exam on Friday at 3pm in CHEM 102

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

CSE 331 Final Exam 3/16/15 Sample Solution

Classes, interfaces, & documentation. Review of basic building blocks

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Tutorial notes on. Object relational structural patterns

What is it? CMSC 433 Programming Language Technologies and Paradigms Spring Approach 1. Disadvantage of Approach 1

Java Object Oriented Design. CSC207 Fall 2014

Inheritance, Polymorphism, and Interfaces

CSE 331 Final Exam 12/9/13

Software Design and Analysis for Engineers

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 10. PUTTING IT ALL TOGETHER. Are we there yet?

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Students received individual feedback throughout year on assignments.

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

Design Patterns: State, Bridge, Visitor

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Rules and syntax for inheritance. The boring stuff

SYSC Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

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

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

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

INHERITANCE AND TYPE HIERARCHIES. Prof. Chris Jermaine

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Everything is an object. Almost, but all objects are of type Object!

CS 251, Intermediate Programming Midterm Exam October 9, 2013

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

CSE351 Winter 2016, Final Examination March 16, 2016

CITS1001 week 4 Grouping objects lecture 2

Chapter 4 Defining Classes I

Procedural Abstraction

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor

EINDHOVEN UNIVERSITY OF TECHNOLOGY

Java Control Statements

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

Survey #2. Programming Assignment 3. Final Exam. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu.

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

16 Multiple Inheritance and Extending ADTs

Inheritance and Interfaces

1 Inheritance (8 minutes, 9 points)

17 Multiple Inheritance and ADT Extensions

CSE 143 Lecture 12 Inheritance

C12a: The Object Superclass and Selected Methods

School of Informatics, University of Edinburgh

CSE 331 Final Exam 3/12/12

COMP12111 Fundamentals of Computer Engineering Paul Nutter Vasilis Pavlidis Comments

COMP 250 Fall inheritance Nov. 17, 2017

5.6.1 The Special Variable this

CSE 143 Sp03 Final Exam Sample Solution Page 1 of 13

Equality for Abstract Data Types

Chapter 6 Introduction to Defining Classes

Marker s feedback version

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

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

ESE115 Introduction to Programming with Java. Midterm 2 November 10, 2005 SOLUTION

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

QUIZ. How could we disable the automatic creation of copyconstructors

05. SINGLETON PATTERN. One of a Kind Objects

XC Total Max Score Grader

Do not turn to the next page until the start of the exam.

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

Model Solutions. COMP 103: Test May, 2013

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

Assignment3 CS206 Intro to Data Structures Fall Part 1 (50 pts) due: October 13, :59pm Part 2 (150 pts) due: October 20, :59pm

10/17/2011. Object Oriented Software Development. Types of interface. Interfaces example

Ticket Machine Project(s)

Introduction to Inheritance

COMP 401 Fall Recitation 7: Factories and Lists

CSE 70 Final Exam Fall 2009

CSSE 220 Day 13. Encapsulation Coupling and Cohesion Scoping. Please download EncapsulationExamples from your SVN

OBJECT ORİENTATİON ENCAPSULATİON

Object-Oriented Programming

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

Relationship of class to object

Inheritance and Substitution (Budd chapter 8, 10)

The University of Nottingham

+ Abstract Data Types

Comp Intermediate Programming EXAM #1 February 16, 2004 Rice University - Instructors: Cox & Nguyen

Assignment 4. Aggregate Objects, Command-Line Arguments, ArrayLists. COMP-202B, Winter 2011, All Sections. Due: Tuesday, March 22, 2011 (13:00)

QUIZ. How could we disable the automatic creation of copyconstructors

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122

Documentation (and midterm review)

S T R U C T U R A L M O D E L I N G ( M O D E L I N G A S Y S T E M ' S L O G I C A L S T R U C T U R E U S I N G C L A S S E S A N D C L A S S D I A

CSE 331 Summer 2016 Final Exam. Please wait to turn the page until everyone is told to begin.

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

Tentamen. DD2385 Software Engineering spring 2015 Friday june 5th The exam has two parts with 30 points each

Polymorphism and Inheritance

CSIS 10B Lab 2 Bags and Stacks

6.005 Elements of Software Construction

Object-oriented Programming and Software Engineering CITS1001. Multiple-choice Mid-semester Test

Transcription:

COMP19612 2011 exam performance feedback Model answers/marking scheme in bold, additional comments in bold italic. Question 2 Only a couple of people did this and neither were close to the right answers. This question is about practical Java programming using loops and arrays You are writing a class which contains information about events and the dates on which they occurred. Events are just Strings. Dates are objects of a class called Date, for which the following items are relevant: The Date class has a method public boolean morerecentthan(date other) which returns true if the Date object the method is called on is more recent than the other Date object It also has a method public boolean equals(date other) which is true if the dates are the same. It has a constant BEGINNING_OF_TIME which is guaranteed to be older than any other Data objects. It has a tostring() method which returns a sensible String representation of a Date. In your class you have an array of Date objects called _dates and an array of Strings called _events. Each element of _dates is the date of the corresponding element of _events, e.g. _dates[3] is the data of _event[3]. 2.1. How would you check whether the fifth date is more recent than the seventh, assuming that there are at least 7 dates. Hint: if you don t know how to do this, it would in inadvisable to continue with this question. 2 marks _dates[4].morereccentthan(dates[6]); 2.2. Write a method public Date mostrecent() which returns the most recent date in the _dates array. Hint: the BEGINNING_OF_TIME constant and the morerecentthan() method are useful here. 4 marks Note: equivalent while or C-style for loops are ok, although students have not been formally taught the latter public Date mostrecent() { Date result = BEGINNING_OF_TIME;

for (Date recent: _dates) { if {recent.morerecentthan(result) { result = recent; 2.3 Write a method public String eventat(date date) which returns the event at the given date, if any (you can assume there is not more than one). If there is no event at that date, it should return the String No event at that date. Hint: the equals() method is useful here. 4 marks Note: this would normally be written with a boolean to stop as soon as a result is found, but I ve not shown them an example like that. They most certainly have not been told about break. public String eventat(date date) { String result = No event at that date ; int i=0; while(i < _dates.length) { if (_dates[i].equals(date)) { result = events[i]; i++; 2.4. Write a method which prints the most recent event and its date on one line. 5 marks public void printmostrecent() { int index = 0;

Date date = BEGIINING_OF_TIME; String event = No event found ; for (Date recent: _dates) { if {recent.morerecentthan(result) { date = recent; event = events[index]; index++; System.out.println(event + date); Question 3 Most people did this question, and it was done fairly well in general. This question is about inheritance. It involves writing code, but you only need to write the code which exactly corresponds to the items mentioned in the question. 3.1 Explain how inheritance in programming languages is related to the way we manage complexity in the real world, and what its main advantages are. 4 marks Bookwork key idea is that one of the ways we manage complexity in the real world is by thinking in terms of concept hierarchies, so use of inheritance in programming is natural. Inheritance provides code reuse, but it s more important to structure our code in a natural way. 3.2 Draw a UML class diagram which shows an abstract class FormOfTransport, with subclasses Bus and Train.. 3 marks Trivial, but must use the notation correct. 3..3 Show how the three classes would be declared in Java. 3 marks public abstract class FormOfTransPort public class Bus extends FormOfTansport public class Train extends FormOfTransport I was pleased how many people got this right, even though it was on a practice test. 3.4 Write the FormOfTransport class, assuming that: - It stores its owner as a String and its capacity as an int - There are public methods to get the owner and the capacity

- There is a method to get its current position, a Position object. This method will be implemented differently in each subclass. 5 marks public abstract class FormOfTransport { private String _owner; private int _capacity; public FrmOfTransport(String owner, int capacity) { _owner = owner; _capacity = capacity; public String getowner() { return _owner; public String getcapacity() { return _capacity; public abstract Position getposition(); I was even more pleased how many people got this right, or at least partially right. Question 4 Only a couple of people attempted this and neither got close to the right answers. This question is about Collections Note. The following description of the Date class is the same as in question 2. You are writing a class which contains information about events and the dates on which they occurred. Events are just Strings. Dates are objects of a class called Date, for which the following items are relevant: The Date class has a method public boolean morerecentthan(date other) which returns true if the Date object the method is called on is more recent than the other Date object It also has a method public boolean equals(date other) which is true if the dates are the same. It has a constant BEGINNING_OF_TIME which is guaranteed to be older than any other Data objects. It has a tostring() method which returns a sensible String representation of a Date. In your class you have two Lists, _dates and _events, where

each element of _dates is the date of the corresponding element of _events, e.g. the third element of _dates s the date of the third element of events. 4.1 How would you declare and initialise the list of dates, assuming that you are using ArrayLists? 2 marks private List<Date> _dates; (in the constructor) _dates = new ArrayList<Date>(); 4.2 How would you check whether the fifth date is more recent than the seventh, assuming that there are at least 7 dates?. 2 marks _dates.get(6).morerecentthan(_dates.get(8)); 4.3 Write a method public String eventat(date date) which returns the event at the given date, if any (you can assume there is not more than one). If there is no event at that date, it should return the String No event at that date. Hint: the equals() method is useful here. 4 marks public String eventat(date date) { String result = No event at that date ; int i=0; while(i < _dates.size()) { if (_dates.get(i).equals(date)) { result = events.get(i); i++; 4.4 Suppose instead of ArrayLists you use a Map, _eventmap from dates to events. 4.4.a Show how this map would be declared and initialised 2 marks Private Map<Date, String> _eventmap; (in the constructor) _eventmap = new HashMap<Date,String>();

4.4 b Show how the eventat method would be implemented using the Map 2 marks public String eventat(date date) { String result = _eventmap.get(date); if (result == null) { result = No event at that date ; else // do nothing { (1 mark if no test for null, i.e.just return _eventmap.get(date)) 4.5 Briefly discuss the advantages of using a Map rather than a pair of ArrayLists.or a pair of arrays. Are there any disadvantages? 3 marks Firstly ArrayLists are better than arrays because it s much easier to add events. The map is much more natural and makes it much easier to get the event at a given date. Operations like mostrecent() can be done with getkeys(). Disadvantage is that it s harder to get the date of an event could fix this with a second map. Question 5 This was done by almost everybody, with mixed results. This question is about data storage 5.1 For three of the four forms of data storage introduced in the course, explain in one sentence how data is stored in that form from a Java program. 3 marks Serialization: just do writeobject to write the root object to an ObjectOutputStream CSV: Write to a text file, typically one line per object XML: Write to a text file, with the appropriate tags and data between then RDB: Use JDBC to insert or update into database tables. A lot of answers said what the forms of data storage were, without specifically saying how data is stored in that format. 5.2 For the same three forms, explain in one sentence how stored data is read back into a Java program. 3 marks Serialization: just do readobject to read the root object from an ObjectIutputStream

CSV: Read a tex file line by line,, typically one line per object XML: Use an XML parser to input the data, then convert it to the objects required RDB: Use JDBC to select from database tables. Here the answers tended more specific, which should have caused people who gave generic answers to the previous part to revisit it. 5.3 Which of the forms is not normally used for long-term data storage, and why? 1 mark Serialization because minor changes in the format of classes can invalidate stored objects (schema evolution). A number of people said CSV here. Although CSV is very simple there s no reason not to use it for long term storage if it is otherwise appropriate. 5.4 The exam software you are using uses all four forms. While you are taking the exam, backups of your work are sent to the server using Java serialization. These backups and exam and answer data generally are stored as XML files on the server. Information about which students are taking which courses etc. (hundreds of thousands of records) are stored in a relational database. Finally, marks are produced as CSV files. 5.4 a. For each of the formats, suggest one reason why we use it in the particular role (i.e. real time data backup, long tern exam data storage, student data storage, result production) stated above. 4 marks Serialization: fast and efficient, doesn t require XML handling on the client side. XML: Compact and efficient, exams are naturally tree structured RDB: Large amount of date, naturally table structure, required proper management CSV: Simple and convenient, can be viewed in Excel. Answers were mostly ok, a few people didn t read the question properly and actually had different formats from those given. 5.4 b For each role, suggest an alternative form of data storage we could have used, briefly explaining why. 4 marks Marks for anything sensible. Only absolute no-no is using serialization for longterm storage. Well actually neither CSV or a database (both of which were suggested) make much sense for backup, XML is the only sensible alternative to serialisation as the data is tree-structured.