Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Model Solutions ENGR 110: Test 2 2 Oct, 2014 Instructions Time allowed: 50 minutes. Closed Book. Answer all the questions. There are 50 marks in total. Write your answers in the boxes in this test paper and hand in all sheets. If you think some question is unclear, ask for clarification. This test contributes 10% of your final grade You may use paper translation dictionaries, and calculators. You may write notes and working on this paper, but make sure your answers are clear. Questions Marks 1. Activity Diagrams [8] 2. Use Case Bodies [10] 3. Use Case Diagrams [7] 4. Class Diagrams: Associations [13] 5. Designing Class Diagrams [12] TOTAL:
JetFlightsNZ JetFlightsNZ airline has a website that enables customers to browse flight routes and book flights within New Zealand. To book a flight customers enter the desired date, destination, and departure city. They then select the flight they want from the list provided to them, and are taken through to the payment page. If the payment is successful, then the flight is booked and the customer is sent a confirmation email with their booking reference details. Having booked a flight, passengers are able to log into the JetFlightsNZ website using their name and booking reference. Once they have logged in, they are able to amend their reservation, by selecting to change either the date or destination city. This enables them to search for an alternative flight, which they can select instead of their existing booking. If the new flight is more expensive than their original flight they have to pay the difference. Once they have logged in, passengers can also select their inflight meal preference, request an upgrade, or cancel the booking completely. Some of these actions require payments (or refunds) to be made securely. ENGR 110 (Terms Test 2) Page 2 of 13 continued...
Student ID:....................... The description of JetFlightsNZ on the facing page is background for questions 1, 2, and 3. ENGR 110 (Terms Test 2) Page 3 of 13 continued...
Question 1. Activity Diagrams [8 marks] [This question refers to the JetFlightsNZ system described on page 2.] Convert the following use case body into an activity diagram, making sure to clearly label the error and alternate sequences. and enters payment details 6. Payment Authorisation System confirms Alternative scenarios A1: Payment details entered incorrectly 1 or 2 times The A1 scenario starts at point 5 of the main success scenario Actions of actors 6. Payment Authorisation System denies Error scenarios E1: There are no upgrade options The E1 scenario starts at point 2 of the main success scenario Actions of actors E2: Payment details entered incorrectly 3 times The E2 scenario starts at point 5 of the main success scenario Actions of actors 6. Payment Authorisation System denies Use case: Request Upgrade Actors: Passenger (primary), Payment Authorisation System (secondary) Preconditions: Logged On Actions of actors Actions of system 1. Passenger selects flight to upgrade 2. System checks to see if this is possible 3. System presents upgrade options and prices to passenger and requests payment details 4. Passenger selects preferred option 5. System requests payment authorisation 7. Passenger details updated, passenger notified. Actions of system 7. System checks that incorrect details entered fewer than 3 times. 8. Go to M.3 Actions of system 3. System notified that there are no upgrade options and the Use Case fails. Actions of system 7. System checks that incorrect details entered 3 times. 8. System notifies Payment Authorisation System, transaction denied, Use Case fails. (Question 1 continued on next page) ENGR 110 (Terms Test 2) Page 4 of 13 continued...
Student ID:....................... (Question 1 continued) Select flight Check for upgrade ok none E 1 Options/ payment presented Start Fail E 2 Details updated Passenger selects & pays A 1 Notification sent End ENGR 110 (Terms Test 2) Page 5 of 13 continued...
Question 2. Use Case Bodies [10 marks] Consider the use case Book flight. Provide the use case body for the main success scenario, and for one alternate or error scenario. NOTE: No marks will be given for an alternative/error scenario copied from Q1. The system description from page 1 is repeated below for convenience. JetFlightsNZ JetFlightsNZ airline has a website that enables customers to browse flight routes and book flights within New Zealand. To book a flight customers enter the desired date, destination, and departure city. They then select the flight they want from the list provided to them, and are taken through to the payment page. If the payment is successful, then the flight is booked and the customer is sent a confirmation email with their booking reference details. Having booked a flight, passengers are able to log into the JetFlightsNZ website using their name and booking reference. Once they have logged in, they are able to amend their reservation, by selecting to change either the date or destination city. This enables them to search for an alternative flight, which they can select instead of their existing booking. If the new flight is more expensive than their original flight they have to pay the difference. Once they have logged in, passengers can also select their inflight meal preference, request an upgrade, or cancel the booking completely. Some of these actions require payments (or refunds) to be made securely. (Question 2 continued on next page) ENGR 110 (Terms Test 2) Page 6 of 13 continued...
Student ID:....................... (Question 2 continued) Use case: Book Flight Actors: Customer (primary), Payment Authorisation System (secondary) Actions of actors Actions of system 1. Customer enters flight details 2. System checks for flights matching (date, destination, and departure) details and presents to user 3. Customer selects flight from list 4. System requests payment details 5. Customer enters payment details 6. System requests payment authorisation 7. Payment Authorisation System 8. Flight booking allocated and details confirms sent to customer by email Error scenario E1: No available flights The E1 scenario starts at point 1 of the main success scenario Actions of actors Actions of system 2. No matching flights available. User notified. The use case fails ENGR 110 (Terms Test 2) Page 7 of 13 continued...
Question 3. Use Case Diagrams [7 marks] Draw a use case diagram for the JetFlight NZ system, making sure to include all 6 Use Cases and all 3 actors. Customer Passenger Browse Book Flight Log on Amend Reservation Select Meal Request Upgrade << ensures logged on>> <<requires logged on>> <<requires logged on>> <<requires logged on>> secondary secondary secondary <<actor>> Payment AS ENGR 110 (Terms Test 2) Page 8 of 13 continued...
Student ID:....................... Question 4. Class Diagrams: Associations [13 marks] (a) [4 marks] Consider the following fragment of a class diagram with two classes and an association: Packet 1 RelatedTo 0..* Company Explain what the multiplicities of the relatedto association mean in terms of individual Packet objects and individual Company objects. Every Packet object is relatedto a collection of Company objects of indefinite size (possibly none). Every Company object is relatedto exactly one Packet object (Question 4 continued on next page) ENGR 110 (Terms Test 2) Page 9 of 13 continued...
(Question 4 continued) (b) [3 marks] Show how the association in the following class diagram could be implemented as field(s) in Java code. Flight BookedOn 0..* Passenger public class Flight { private List <Passenger> bookedon= new ArrayList<Passenger>(); } public class Passenger { } (c) [3 marks] Show how the association in the following class diagram could be implemented as field(s) in Java code. Flight 1 flight BookedOn 0..* passengers Passenger public class Flight { private List <Passenger> passengers = new ArrayList<Passenger>(); } public class Passenger { private Flight flight ; } (Question 4 continued on next page) ENGR 110 (Terms Test 2) Page 10 of 13 continued...
Student ID:....................... (Question 4 continued) (d) [3 marks] How could your implementation enforce the multiplicity of 1 in the BookedOn association in (c)? The flight field only holds one Flight object, so the maximum of 1 Flight per Passenger is enforced automatically in the Passenger class. To ensure that the minimum of 1 Flight per passenger is enforced, the Passenger constructor would need to have a parameter that takes a Flight object, and would then check that the Flight value was not null and assign it to the flight field. Additional, more subtle requirements: If the Passenger class has a method for changing the flight field, that method would need to ensure that it did not change the field to null. The program would need to have methods for adding or removing a Passenger to the list of passengers in a Flight. These methods would have to ensure the Passenger was always in the list of exactly one Flight - never adding it to one list without removing from another list, and vice versa. [Full marks did not require the last point to be stated.] ENGR 110 (Terms Test 2) Page 11 of 13 continued...
Question 5. Designing Class Diagrams [12 marks] (a) [10 marks] Draw a class diagram with three classes for the following ground traffic control system. You should include associations, and at most one attribute and one operation per class. An airport has several gates, numbered 1, 2, 3,.... Each gate always has one service vehicle allocated to it. Each arriving aircraft (identified by its flight number), is assigned a gate. There may be several aircraft assigned to a single gate, but there can only be one aircraft parked at the gate at a time; other aircraft assigned to the gate have to wait their turn before they can park. When an aircraft parks at its gate, the ground control system can assign a list of tasks to the service vehicle for it to perform on the aircraft. Gate GateNumber : integer 0..1 AllocatedVehicle AllocatedGate 1 0..* ParkedAt 0..1 Aircraft FlightNumber : String park(gate gate) ServiceVehicle 1 assigntasks(list<string>) (Question 5 continued on next page) ENGR 110 (Terms Test 2) Page 12 of 13 continued...
Student ID:....................... (Question 5 continued) The following class diagram describes part of the design for an airline booking system which expresses the fact that there are two kinds of passengers regular passengers and first-class passengers and that first-class passengers are able to some do actions that regular passengers cannot. (Note, no attributes or associations are shown in this diagram.) Passenger setdietaryrequirements() : String cancelflight() FirstClassPassenger choosemeal() booklounge() requestlimousine() (b) [2 marks] Explain why this design would be hard to implement in Java if passengers are allowed to upgrade from regular to first-class. Java does not allow you to change the type of an object once it has been constructed, so upgrading a Passenger object would mean removing the object and replacing it (everywhere) by a new FirstClassPassenger object which had the values in the original Passenger object copied over to the new FirstClassPassenger object. Constructing a new object is not difficult, but identifying all the places in the program where a reference to the previous Passenger object is stored, and replacing them by the new object is likely to be difficult, and would be more difficult to keep it true as the program is extended and modified. A much better scheme would be to have a field in the passenger object to record whether it is first class or not, and make the methods (the ones that are associated with first class passengers only) first check the field to make sure they are applicable. [Only the issue in the first paragraph was required for full marks] * * * * * * * * * * * * * * * ENGR 110 (Terms Test 2) Page 13 of 13