G52CON 2008-2009 Coursework: Hotel Room Booking System

The coursework involves writing a Java Hotel class which has methods to book rooms and check room bookings which could be called concurrently by multiple threads. Your task is to make sure there is no interference between threads (for example, no double-bookings) and at the same time maximum concurrency is allowed in the implementation of the class. Your solution should be accompanied by 1- or 2-page explanation of your program. The program and the essay are marked together (there is no fixed split of marks between them).

Each hotel contains zero or more rooms and each room has a unique room number (the room numbers are not necessarily consecutive). Multiple users interact with the booking system to check the availability of rooms and to make bookings. Each booking has a unique booking reference generated by the clients of the booking system. Rooms can be booked for one or more (not necessarily consecutive) days. A booking can be for a single room, or (optionally) for several rooms on the specified day or days. Days are numbered sequentially from 0 (corresponding to some arbitrary date, e.g., 01/01/1970) and bookings can be arbitrarily far in the future.

Design and implement a Java Hotel class which provides the following public methods:

Note that the methods do not throw any checked exceptions other than those specified.  A NoSuchBookingException class is provided as part of the coursework.

For extra credit you may optionally also provide methods:

If you are implementing the extended specification, the specification of the cancelBooking() method becomes:

Your implementation should allow safe concurrent access to instances of the Hotel class by multiple threads.

Notes

The aim of the coursework is to gain experience in writing concurrent programs, not to produce a fully functional hotel booking system. Basically you need to write a class which stores information about relationship between booking references (Strings), rooms (ints), and which days they are booked for (ints). Please don't be tempted to over-interpret the problem, e.g., by introducing "real" dates, or a user interface (in the code you submit). Similarly, any  code submitted which requires user input will fail the automated tests. If you develop test cases or a test harness, keep this separate from the code you submit and don't include it in your submission. Here is a very simple test harness which is mostly given for you to check that your method signatures are correct (and give an example of what the threads might be doing to instances of your Hotel class). You may find the JUnit testing framework and its multi-threaded extensions useful while developing your code.

The methods throw no checked exceptions other than those specified. You may assume that the dates and room numbers supplied as arguments are valid and booking references are unique. (This is arguably bad practice, but it simplifies things.) The set of possible days and rooms does not change during the execution of the program. However the set of bookings does change. For example, it is important to distinguish the case where a booking could not be updated because the new dates or room(s) conflict which an existing booking, and the case in which the booking cannot be updated because it hasn't been created yet (by bookRoom()) or has already been deleted (by cancelBooking()). updateBooking() and cancelBooking() should therefore throw NoSuchBookingException if the specified booking doesn't exist.

Submission

The submission consists of two parts:

  1. the code implementing the Hotel class (in a single file called Hotel.java or in several files one of which is called Hotel.java); and
  2. an essay explaining your solution and why it is correct (in pdf format: submissions in other formats will not be marked).

Submissions are due at 23:59 on Friday the 20th of March to the cw system (coursework ID is 190). Added 20 March: Late submission is possible, reduction in marks is standard, -5 for every working day late.

Assessment

Marking will be based on the correctness and clarity of your solution, the degree of concurrent access it allows, and the correctness and clarity of the your explanation of the code. A correct solution will pass, but for a higher mark you solution should also maximise concurrency.  There will be a (small) prize for the best solution.

You are reminded of the School's Policy on Plagiarism. For the purposes of this coursework, the policy shall be interpreted as follows.

Your code should be written entirely by you. You may discuss algorithms and source material, but you should write your own code independently. Do not under any circumstances show your code to another student, look at another student's code, or allow through negligence another student to see your code.

You may make use of material from other sources (e.g. textbooks or class libraries) so long as this is properly cited. Any material not written by you and included in your submission without due reference to the source is a case of plagiarism. To give due reference in text you should place the quotation in italics and surround it by quotation marks and provide full reference details to the source. To give due reference to source code you should place comments at the start and end of the code fragment that you have copied. These comments should give a clear reference to the source of the code, and the extent of the code which you have not written yourself. The only code that you may use without reference is that provided in the module lectures or the coursework web page, and the standard Java libraries.

This file is maintained by Natasha Alechina, last modified 11:14, 27-Feb-2009.