Software and Languages

A Hotel System

Hotel
This small teaching module (a zipped folder) can be used to introduce studens to the relationship between Java and UML class models. It is a fully functioning Java program that implements a hotel booking system. The program can print out its current state in an XML format which is useful to show students before and after snapshots of the system. The material comes with a small number of slides that can be used as the basis of teaching materials together with some student activities that involve extending the basic models and software. Solutions to all the student activities are provided in a copy of the module in the root folder. The class models can be viewed using StarUML.

Here is an example of the controller for the booking system:
import xml.XMLOutput;
import hotel.BookingSystem;
import hotel.RoomType.Type;

public class Main {

public static void main(String[] args) {

// Create a target for the XML output...

XMLOutput xml = new XMLOutput();

// Create a new booking system...

BookingSystem bookingSystem = new BookingSystem();

// Show the empty system...

bookingSystem.xml(xml);
System.out.println("Nothing defined yet...\n" + xml);

// Create some hotels and get their ids...

int h1 = bookingSystem.addHotel("FleaPit Towers", "London");
int h2 = bookingSystem.addHotel("Comfy Cribs", "London");
int h3 = bookingSystem.addHotel("FleaPit Towers", "Manchester");

// Show just the hotels...

bookingSystem.xml(xml);
System.out.println("\n\nSome hotels...\n" + xml);

// Populate the hotels with some rooms...

int r1 = bookingSystem.addRoom(h1, Type.Single, 1, 150.0);
int r2 = bookingSystem.addRoom(h1, Type.Double, 2, 250.0);
int r3 = bookingSystem.addRoom(h1, Type.Double, 3, 250.0);

int r4 = bookingSystem.addRoom(h2, Type.Single, 1, 200.0);
int r5 = bookingSystem.addRoom(h2, Type.Double, 2, 350.0);
int r6 = bookingSystem.addRoom(h2, Type.Double, 3, 350.0);

// Show the populated hotels...

bookingSystem.xml(xml);
System.out.println("\n\nSome hotels with rooms...\n" + xml);

// Register some customers...

int c1 = bookingSystem.registerCustomer("Fred", "10 Main St., Manchester");
int c2 = bookingSystem.registerCustomer("Sally", "10 Main St., Leeds");
int c3 = bookingSystem.registerCustomer("Bill", "10 Main St., Edinburgh");

// Show the customers...

bookingSystem.xml(xml);
System.out.println("\n\nSome customers have registered...\n" + xml);

// Create some bookings...

int b1 = bookingSystem.book(c1, h1, 1, "01/01/2009");
int b2 = bookingSystem.book(c2, h2, 2, "02/01/2009");
int b3 = bookingSystem.book(c3, h2, 3, "03/02/09");

// Show the bookings...

bookingSystem.xml(xml);
System.out.println("\n\nSome bookings...\n" + xml);

// The customer arrives and books-in with the front desk of the hotel...

bookingSystem.arrive(b1, "21/02/2009");
bookingSystem.arrive(b2, "22/02/2009");

// Show the arrivals...

bookingSystem.xml(xml);
System.out.println("\n\nSome customers have arrived...\n" + xml);

// Hotel facilities are used via the booking number (on the key card)..

bookingSystem.useSpa(b1, 200.0);
bookingSystem.buyDrink(b1, 10.0);
bookingSystem.buyMeal(b2, 25.0);

// Show the use of the facilities...

bookingSystem.xml(xml);
System.out.println("\n\nCustomers have used the facilities...\n" + xml);

// Checkout via the booking number, supplying some funds...

bookingSystem.checkout(b1, 1000.0, "22/02/2009");
bookingSystem.checkout(b2, 1000.0, "22/02/2009");

// Show the final state...

bookingSystem.xml(xml);
System.out.println("\n\nAfter checkouts...\n" + xml);

}

}
... and here is the output:
Nothing defined yet...
<System>
<Current/>
<History/>
</System>


Some hotels...
<System>
<Hotel id='0' name='FleaPit Towers' address='London'/>
<Hotel id='1' name='Comfy Cribs' address='London'/>
<Hotel id='2' name='FleaPit Towers' address='Manchester'/>
<Current/>
<History/>
</System>


Some hotels with rooms...
<System>
<Hotel id='0' name='FleaPit Towers' address='London'>
<Room id='3' number='1'>
<Single price='150.0'/>
</Room>
<Room id='4' number='2'>
<Double price='250.0'/>
</Room>
<Room id='5' number='3'>
<Double price='250.0'/>
</Room>
</Hotel>
<Hotel id='1' name='Comfy Cribs' address='London'>
<Room id='6' number='1'>
<Single price='200.0'/>
</Room>
<Room id='7' number='2'>
<Double price='350.0'/>
</Room>
<Room id='8' number='3'>
<Double price='350.0'/>
</Room>
</Hotel>
<Hotel id='2' name='FleaPit Towers' address='Manchester'/>
<Current/>
<History/>
</System>


Some customers have registered...
<System>
<Customer id='9' name='Fred' address='10 Main St., Manchester'/>
<Customer id='10' name='Sally' address='10 Main St., Leeds'/>
<Customer id='11' name='Bill' address='10 Main St., Edinburgh'/>
<Hotel id='0' name='FleaPit Towers' address='London'>
<Room id='3' number='1'>
<Single price='150.0'/>
</Room>
<Room id='4' number='2'>
<Double price='250.0'/>
</Room>
<Room id='5' number='3'>
<Double price='250.0'/>
</Room>
</Hotel>
<Hotel id='1' name='Comfy Cribs' address='London'>
<Room id='6' number='1'>
<Single price='200.0'/>
</Room>
<Room id='7' number='2'>
<Double price='350.0'/>
</Room>
<Room id='8' number='3'>
<Double price='350.0'/>
</Room>
</Hotel>
<Hotel id='2' name='FleaPit Towers' address='Manchester'/>
<Current/>
<History/>
</System>


Some bookings...
<System>
<Customer id='9' name='Fred' address='10 Main St., Manchester'/>
<Customer id='10' name='Sally' address='10 Main St., Leeds'/>
<Customer id='11' name='Bill' address='10 Main St., Edinburgh'/>
<Hotel id='0' name='FleaPit Towers' address='London'>
<Room id='3' number='1'>
<Single price='150.0'/>
</Room>
<Room id='4' number='2'>
<Double price='250.0'/>
</Room>
<Room id='5' number='3'>
<Double price='250.0'/>
</Room>
</Hotel>
<Hotel id='1' name='Comfy Cribs' address='London'>
<Room id='6' number='1'>
<Single price='200.0'/>
</Room>
<Room id='7' number='2'>
<Double price='350.0'/>
</Room>
<Room id='8' number='3'>
<Double price='350.0'/>
</Room>
</Hotel>
<Hotel id='2' name='FleaPit Towers' address='Manchester'/>
<Current>
<Booking dateBooked='Thu Jan 01 00:00:00 GMT 2009' dateArrived='' checkOut='' customer='9' room='3' cost='0.0'/>
<Booking dateBooked='Fri Jan 02 00:00:00 GMT 2009' dateArrived='' checkOut='' customer='10' room='7' cost='0.0'/>
<Booking dateBooked='Sun Feb 03 00:00:00 GMT 9' dateArrived='' checkOut='' customer='11' room='8' cost='0.0'/>
</Current>
<History/>
</System>


Some customers have arrived...
<System>
<Customer id='9' name='Fred' address='10 Main St., Manchester'/>
<Customer id='10' name='Sally' address='10 Main St., Leeds'/>
<Customer id='11' name='Bill' address='10 Main St., Edinburgh'/>
<Hotel id='0' name='FleaPit Towers' address='London'>
<Room id='3' number='1'>
<Single price='150.0'/>
</Room>
<Room id='4' number='2'>
<Double price='250.0'/>
</Room>
<Room id='5' number='3'>
<Double price='250.0'/>
</Room>
</Hotel>
<Hotel id='1' name='Comfy Cribs' address='London'>
<Room id='6' number='1'>
<Single price='200.0'/>
</Room>
<Room id='7' number='2'>
<Double price='350.0'/>
</Room>
<Room id='8' number='3'>
<Double price='350.0'/>
</Room>
</Hotel>
<Hotel id='2' name='FleaPit Towers' address='Manchester'/>
<Current>
<Booking dateBooked='Thu Jan 01 00:00:00 GMT 2009' dateArrived='Sat Feb 21 00:00:00 GMT 2009' checkOut='' customer='9' room='3' cost='3600.0'/>
<Booking dateBooked='Fri Jan 02 00:00:00 GMT 2009' dateArrived='Sun Feb 22 00:00:00 GMT 2009' checkOut='' customer='10' room='7' cost='8050.0'/>
<Booking dateBooked='Sun Feb 03 00:00:00 GMT 9' dateArrived='' checkOut='' customer='11' room='8' cost='0.0'/>
</Current>
<History/>
</System>


Customers have used the facilities...
<System>
<Customer id='9' name='Fred' address='10 Main St., Manchester'/>
<Customer id='10' name='Sally' address='10 Main St., Leeds'/>
<Customer id='11' name='Bill' address='10 Main St., Edinburgh'/>
<Hotel id='0' name='FleaPit Towers' address='London'>
<Room id='3' number='1'>
<Single price='150.0'/>
</Room>
<Room id='4' number='2'>
<Double price='250.0'/>
</Room>
<Room id='5' number='3'>
<Double price='250.0'/>
</Room>
</Hotel>
<Hotel id='1' name='Comfy Cribs' address='London'>
<Room id='6' number='1'>
<Single price='200.0'/>
</Room>
<Room id='7' number='2'>
<Double price='350.0'/>
</Room>
<Room id='8' number='3'>
<Double price='350.0'/>
</Room>
</Hotel>
<Hotel id='2' name='FleaPit Towers' address='Manchester'/>
<Current>
<Booking dateBooked='Thu Jan 01 00:00:00 GMT 2009' dateArrived='Sat Feb 21 00:00:00 GMT 2009' checkOut='' customer='9' room='3' cost='3810.0'>
<Spa cost='200.0'/>
<Drink cost='10.0'/>
</Booking>
<Booking dateBooked='Fri Jan 02 00:00:00 GMT 2009' dateArrived='Sun Feb 22 00:00:00 GMT 2009' checkOut='' customer='10' room='7' cost='8075.0'>
<Meal cost='25.0'/>
</Booking>
<Booking dateBooked='Sun Feb 03 00:00:00 GMT 9' dateArrived='' checkOut='' customer='11' room='8' cost='0.0'/>
</Current>
<History/>
</System>


After checkouts...
<System>
<Customer id='9' name='Fred' address='10 Main St., Manchester'/>
<Customer id='10' name='Sally' address='10 Main St., Leeds'/>
<Customer id='11' name='Bill' address='10 Main St., Edinburgh'/>
<Hotel id='0' name='FleaPit Towers' address='London'>
<Room id='3' number='1'>
<Single price='150.0'/>
</Room>
<Room id='4' number='2'>
<Double price='250.0'/>
</Room>
<Room id='5' number='3'>
<Double price='250.0'/>
</Room>
</Hotel>
<Hotel id='1' name='Comfy Cribs' address='London'>
<Room id='6' number='1'>
<Single price='200.0'/>
</Room>
<Room id='7' number='2'>
<Double price='350.0'/>
</Room>
<Room id='8' number='3'>
<Double price='350.0'/>
</Room>
</Hotel>
<Hotel id='2' name='FleaPit Towers' address='Manchester'/>
<Current>
<Booking dateBooked='Sun Feb 03 00:00:00 GMT 9' dateArrived='' checkOut='' customer='11' room='8' cost='0.0'/>
</Current>
<History>
<Booking dateBooked='Thu Jan 01 00:00:00 GMT 2009' dateArrived='Sat Feb 21 00:00:00 GMT 2009' checkOut='Sun Feb 22 00:00:00 GMT 2009' customer='9' room='3' cost='360.0'>
<Spa cost='200.0'/>
<Drink cost='10.0'/>
</Booking>
<Booking dateBooked='Fri Jan 02 00:00:00 GMT 2009' dateArrived='Sun Feb 22 00:00:00 GMT 2009' checkOut='Sun Feb 22 00:00:00 GMT 2009' customer='10' room='7' cost='25.0'>
<Meal cost='25.0'/>
</Booking>
</History>
</System>