Linköpings Universitet IDA SaS PELAB Kristian Sandahl 2003-10-21 Written examination TDDB62 Software Engineering for I Date: Saturday 2003-10-25 Time: 14:00-18:00 Allowed aids: One textbook of the Student’s choice. Hand-written notes in the book pages are allowed. Dictionaries from English to another language without notes are allowed. Explicitly forbidden aids: Electronic equipment, separate sheets of papers even if they are glued in the book. Writing: Please write or print clearly. We will not give credit for unreadable answers. You may write answers in English or Swedish. Questions should be answered on separate sheets of A4 paper. Write only on one side of the paper and label all papers with name and personal number. When grading the answers we will split on questions, so if we find more than one question on the paper grading will be delayed. Results: The graded exams are shown and handed out Friday 2003-11-07 between 10:15-12:30 in Conference room Allen Newell, E-house, entrance 27 or 29, 1st floor, corridor G. Questions: Kristian Sandahl can be reached at 0706-68 19 57, 013-12 42 53 or 013-711 47 during the examination. Answer as many as possible of the questions 1-10. They probably require only a few lines answer. Each of the questions can give you 2 (two) credits. Answer no more than two of the questions 11-15. They require a thorough answer of a few pages each. Each of the questions can give you 10 (ten) credits. Grading: Credits 40 34-40 31-33 28-30 24-27 20-23 <20 Good luck! Grade Max 5 4 4 3 3 No pass ECTS Max A B C D E F Questions: Answer as many as possible of questions 1-10. Each question gives a maximum of 2 credits. The answers should be focused and short. 1. Which two statements are true? (One or more false statements given = 0 credits; only one statement given that is correct = 1 credit) Suppose you are working in a development company with 20 other people, then: a. it is practically feasible to handle the requirements without a dedicated requirements tool. b. it is practically feasible to handle the processes without a dedicated process assistant tool. c. it is practically feasible to handle different versions of components and releases without a dedicated configuration management tool. d. it is practically feasible to handle regression testing without a dedicated tool for automatic testing. 2. Which two statements are true? (One or more false statements given = 0 credits; only one statement given that is correct = 1 credit) a. High cohesion within components in a system not necessary for good maintenance. b. High cohesion within components in a system is necessary for good maintenance. c. High cohesion within components in a system follows logically from low coupling between components. d. High cohesion within components and low coupling between components in a system makes it possible for relatively more maintainers to work with the system in parallel. 3. Write down two advantages of using an Interface Definition Language (IDL) in Component-Based Software Engineering. 4. Write down two advantages of recording types of faults found during testing. 5. Write down two factors that contribute to the cost of inspections of code that do not occur in executing testing. 6. Draw a state-diagram with labels and at least three states of a rental car. 7. Write down four bad things displayed in the following set of requirements: (exclude shortcomings of grammar, spelling and layout) The administrator logs into the system with a user-id and a password. The administrator should be able to change the teachers’ constraints. (Req. 2) Examiners should be notified if the administrator changed their constraints within reasonable time. (Req. 3) 8. Write down two approaches to cost estimation of software. Invent and write down an example of when one of the approaches is better than the other. Write down a motivation. 9. Maintenance is an important part of software engineering. Your task is to extend the functionallity of the system on next page, by adding the following method to the Library-class: int count(String title) - Returns the number of books that has the given title. Write the method in as correct Java as possible. If needed, write pseudo code. Documentation of the class Vector is available as an appendix to the exam. 10. Your task is to extend the functionallity of the system on next page, by adding the following method to the Library-class: void banAuthor(String author) - Removes all books written by the given author from the library. Write the method in as correct Java as possible. If needed, write pseudo code. Documentation of the class Vector is available as an appendix to the exam. System for questions 9 & 10 import java.util.Vector; public class Library { Vector books; public Library() { books = new Vector(); } public void addBook(Book b) { books.add(b); } public int countBooks() { return books.size(); } public Vector search(String author) { Vector result = new Vector(); for(int i = 0 ; i < books.size() ; i++) { Book b = (Book) books.elementAt(i); if(b.isWrittenBy(author)) { result.add(b.getAuthor()); } } return result; } } class Book { private String title; private String author; public Book(String name, String author) { this.title = name; this.author = author; } public String getAuthor() { return author; } public String getTitle() { return title; } public boolean isWrittenBy(String name) { return name.equals(author); } } Answer no more than two of the questions 11-15. Each question gives a maximum of 10 credits. Try to formulate with your own wording. We will be reluctant to give more than 7 credits to solutions that mostly cite sections of the book. The answers should be thorough and complete. 11. Write down a short description and a list of advantages and drawbacks of the following process models: a. Microsoft’s synchronise & stabilise method b. Cleanroom c. Open source development d. Agile methods, such as XP (eXtreme Programming) e. Spiral model 12. Your company is developing components for university administration. Now, you have decided that components should be developed for future reuse and you need to convince the rest of the people about this. Therefore you create a short presentation with 4-5 OH-slides. Write down the text you decide that should go into these slides. Put special attention to the potential advantages of the approach as well as the extra things you need to take into the development projects to accomplish your goal. End the presentation with a formula estimating the pay-off time with developing for reuse. 13. For each of the applications in the list below, select suitable software architecture and write down and motivate your choice. The applications are: • A data conversion application which takes a file of students on the format <firstname1>,<familyname1>,<loginid1>@student.liu.se, <firstname2>,<familyname2>,<loginid2>@student.liu.se, etc. for example Kalle,Anka,kalan313@student.liu.se and generates a file on the format <loginid1>,<familyname1>,<firstname1>,<loginid1>@student.liu.se,<passwo rd>, <loginid2>,<familyname2>,<firstname2>,<loginid2>@student.liu.se,<passwo rd>, etc. for example kalan313,Anka,Kalle,kalan313@student.liu.se,sune • • A cruise control system for a car. If you invoke the system while driving faster than 50 km/h the car will automatically keep the current speed. If you touch the brake or clutch pedal you will turn the control system off. If you resume the system it will maintain the previously maintained speed. A platform for collaborative software design. The programmers work at different offices in Sweden, but need to cooperate an hour a day when trying to integrate and test their individual components on a common server. 14. Create and write down a process for changing requirements. You may assume an information system with about 10 components and that changes occur after the design phase. The entire system is developed at a single company with one department for each component and a technical support department. Put special attention of communication and quality assurance. 15. Write down examples of pairs of conflicting quality factors with a motivation of why they are conflicting. You should also give an example of how the conflicts appear. Appendix: An abridged version of the documentation for the class java.util.Vector. public class Vector extends AbstractList implements List, RandomAccess, Cloneable, Serializable The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrement. The capacity is always at least as large as the vector size; it is usually larger because as components are added to the vector, the vector’s storage increases in chunks the size of capacityIncrement. An application can increase the capacity of a vector before inserting a large number of components; this reduces the amount of incremental reallocation. Fields protected Object[] elementData The array buffer into which the components of the vector are stored. The capacity of the vector is the length of this array buffer, and is at least large enough to contain all the vector's elements. Any array elements following the last element in the Vector are null. protected int elementCount The number of valid components in this Vector object. Components elementData[0] through elementData[elementCount-1] are the actual items. protected int capacityIncrement The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity. If the capacity increment is less than or equal to zero, the capacity of the vector is doubled each time it needs to grow. Constructors public Vector(int initialCapacity) Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero. Parameters: initialCapacity - the initial capacity of the vector. Throws: IllegalArgumentException - if the specified initial capacity is negative public Vector() Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero. Methods public void setSize(int newSize) Sets the size of this vector. If the new size is greater than the current size, new null items are added to the end of the vector. If the new size is less than the current size, all components at index newSize and greater are discarded. Parameters: newSize - the new size of this vector. Throws: ArrayIndexOutOfBoundsException - if new size is negative. public int capacity() Returns the current capacity of this vector. Returns: the current capacity (the length of its internal data array, kept in the field elementData of this vector). public int size() Returns the number of components in this vector. Returns: the number of components in this vector. public boolean isEmpty() Tests if this vector has no components. Specified by: isEmpty in interface List Overrides: isEmpty in class AbstractCollection Returns: true if and only if this vector has no components, that is, its size is zero; false otherwise. public Enumeration elements() Returns an enumeration of the components of this vector. The returned Enumeration object will generate all items in this vector. The first item generated is the item at index 0, then the item at index 1, and so on. Returns: an enumeration of the components of this vector. public boolean contains(Object elem) Tests if the specified object is a component in this vector. Parameters: elem - an object. Returns: true if and only if the specified object is the same as a component in this vector, as determined by the equals method; false otherwise. public int indexOf(Object elem) Searches for the first occurence of the given argument, testing for equality using the equals method. Parameters: elem - an object. Returns: the index of the first occurrence of the argument in this vector, that is, the smallest value k such that elem.equals(elementData[k]) is true; returns -1 if the object is not found. public Object elementAt(int index) Returns the component at the specified index. This method is identical in functionality to the get method (which is part of the List interface). Parameters: index - an index into this vector. Returns: the component at the specified index. Throws: ArrayIndexOutOfBoundsException - if the index is negative or not less than the current size of this Vector object. given. public Object firstElement() Returns the first component (the item at index 0) of this vector. Returns: the first component of this vector. Throws: NoSuchElementException - if this vector has no components. public Object lastElement() Returns the last component of the vector. Returns: the last component of the vector, i.e., the component at index size() - 1. Throws: NoSuchElementException - if this vector is empty. public void setElementAt(Object obj, int index) Sets the component at the specified index of this vector to be the specified object. The previous component at that position is discarded. The index must be a value greater than or equal to 0 and less than the current size of the vector. This method is identical in functionality to the set method (which is part of the List interface). Note that the set method reverses the order of the parameters, to more closely match array usage. Note also that the set method returns the old value that was stored at the specified position. Parameters: obj - what the component is to be set to. index - the specified index. Throws: ArrayIndexOutOfBoundsException - if the index was invalid. public void removeElementAt(int index) Deletes the component at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously. The size of this vector is decreased by 1. The index must be a value greater than or equal to 0 and less than the current size of the vector. This method is identical in functionality to the remove method (which is part of the List interface). Note that the remove method returns the old value that was stored at the specified position. Parameters: index - the index of the object to remove. Throws: ArrayIndexOutOfBoundsException - if the index was invalid. public void addElement(Object obj) Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity. This method is identical in functionality to the add(Object) method (which is part of the List interface). Parameters: obj - the component to be added. public boolean removeElement(Object obj) Removes the first (lowest-indexed) occurrence of the argument from this vector. If the object is found in this vector, each component in the vector with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously. This method is identical in functionality to the remove(Object) method (which is part of the List interface). Parameters: obj - the component to be removed. Returns: true if the argument was a component of this vector; false otherwise. public void removeAllElements() Removes all components from this vector and sets its size to zero. This method is identical in functionality to the clear method (which is part of the List interface). See Also: clear() public Object get(int index) Returns the element at the specified position in this Vector. Parameters: index - index of element to return. Returns: object at the specified index Throws: ArrayIndexOutOfBoundsException - index is out of range (index < 0 || index >= size()). public boolean add(Object o) Appends the specified element to the end of this Vector. Parameters: o - element to be appended to this Vector. Returns: true (as per the general contract of Collection.add). public boolean remove(Object o) Removes the first occurrence of the specified element in this Vector If the Vector does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))) (if such an element exists). Parameters: o - element to be removed from this Vector, if present. Returns: true if the Vector contained the specified element. public Object remove(int index) Removes the element at the specified position in this Vector. shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the Vector. Parameters: index - the index of the element to removed. Returns: element that was removed Throws: ArrayIndexOutOfBoundsException - index out of range (index < 0 || index >= size()). public void clear() Removes all of the elements from this Vector. The Vector will be empty after this call returns (unless it throws an exception) public boolean removeAll(Collection c) Removes from this Vector all of its elements that are contained in the specified Collection. Parameters: c - a collection of elements to be removed from the Vector Returns: true if this Vector changed as a result of the call. Throws: NullPointerException - if the specified collection is null.