test2_solution

test2_solution - CSE 1030 Introduction to Computer Science...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 1030 Introduction to Computer Science II Test 2 10:30 — 11:30, May 1, 2009 Last name First name Student number Instructions No questions are allowed during the test. This is a closed book test. No aids are permitted. Answer each question in the space provided. Make sure that you have answered all 5 questions. Manage your time carefully—you do not need to answer the questions in order. Do not leave during the last 5 minutes; stay seated and do not talk until all of the tests have been collected. Question Total marks available Mark 1 12 2 18 3 10 4 15 5 15 Total 70
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1. [12 marks] Suppose a Person has-an age, has-a name, and has-a date of birth: public class Person { private int age; private String name; private Date birthday; // … } a) [4 marks] Which of the three attributes do not suffer from privacy leaks? Explain why. Recall that a privacy leak is when a client obtains a reference to a private attribute. age, because it is a primitive type and Java uses pass-by-value. name, because it is immutable and immutable objects can be freely shared. b) [2 marks] Should Person use composition with any of the attributes? Which ones? Explain why. Recall that composition implies ownership; that is the Person object is responsible for the attribute. birthday, because Date is mutable c) [3 marks] Complete the following constructor so that Person does not have any privacy leaks; the first attribute is done for you. You do not need to use mutator methods. public Person(int age, String name, Date birthday) { this.age = age; this.name = name; this.birthday = new Date(birthday.getTime()); } d) [3 marks] Complete the following two accessors so that Person does not have any privacy leaks. public String getName() { return this.name; } public Date getDate() { return new Date(this.birthday.getTime()); }
Background image of page 2
2. [18 marks] Questions 2, 3, and 5 refer to the classes Appointment and AppointmentsCalendar . You will find the implementation of both of these classes on the last page of this test. a) [3 marks] Complete the UML class diagram for the Appointment class. b) [4 marks] Complete the UML class diagram for the AppointmentsCalendar class. c) [2 marks] AppointmentsCalendar promises that it always maintains the appointments in chronological order (sorted by time of the appointment). Can the implementation that was provided to you keep such a promise? Why or why not? The intent of this question was to see if you realized that the iterator method exposes references to
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/13/2011 for the course CSE 2011 taught by Professor Someone during the Winter '10 term at York University.

Page1 / 10

test2_solution - CSE 1030 Introduction to Computer Science...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online