marți, 5 iunie 2012

Hotel

package pack;

public aspect CheckInCustomer {

   

    private Customer Room.checkBy = null;

   

    public Customer Room.getCheckBy() {

          return checkBy;

    }

   

    public void Room.setCheckBy(Customer value) {

          checkBy = value;

    }

   

    public void Room.uncheck() {

          setCheckBy(null);

    }

   

    public void StaffHandler.makeCheckIn(Reservation res) {

          res.getRoom().setCheckBy(res.getCustomer());

          //consume reservation

          getReservations().remove(res);

    }

}


............................
package pack;

public aspect CheckOutCustomer {

   

    public void StaffHandler.makeChekcOut(Room room) {

          room.uncheck();

          room.setAvailability(true);

    }

}


..............................
package pack;

public class Customer {

    private int id;

   

    public int getId() {

          return id;       

    }

   

    public Customer(int id) {

          this.id = id;

    }

}

..............................
package pack;

public class Reservation {

   

    private Room room;

    private Customer customer;

   

    public Room getRoom() {

          return room;

    }

   

    public Customer getCustomer() {

          return customer;

    }

   

    public Reservation(Room room, Customer customer) {

          this.room = room;

          this.customer = customer;

    }

}


............................
package pack;

public aspect ReserveRoomAspect {

   

    private boolean Room.available;    



    public void Room.setAvailability(boolean value) {

          available = value;

    }

   

    public boolean Room.isAvailable() {

          return available;

    }

   

    private Room StaffHandler.getAvailableRoom(RoomCategory categ) {

          for(Room room : getRooms()) {

                if (room.isAvailable() && room.getCateg() == categ) {

                      return room;

                }

          }

          return null;

    }

   

    public void StaffHandler.makeReservation(Customer customer, RoomCategory categ) {

          Room foundRoom = getAvailableRoom(categ);

          if (foundRoom != null) {

                Reservation res = new Reservation(foundRoom, customer);

                getReservations().add(res);

                foundRoom.setAvailability(false);

          }

    }

}

.....................................
package pack;

public class Room {

    private int nr;

    private RoomCategory categ;

   

    public int getNr() {

          return nr;

    }

   

    public RoomCategory getCateg() {

          return categ;

    }

   

    public Room(int nr, RoomCategory categ) {

          this.nr = nr;

          this.categ = categ;

    }

}

..............................
package pack;

public enum RoomCategory {

   

    A(10),

    B(20),

    C(30),

    D(40);

   

    private int price;

   

    public int price() {

          return price;

    }

   

    private RoomCategory(int price) {

          this.price = price;

    }

}

.........................
package pack;

import java.util.*;



public class StaffHandler {



      private List<Room> rooms = new ArrayList<Room>();

      private List<Reservation> reservations = new ArrayList<Reservation>();



      public StaffHandler() {

            testInits();

      }

     

      public List<Room> getRooms() {

            return rooms;

      }

     

      public List<Reservation> getReservations() {

            return reservations;

      }



      private void testInits() {

            for (int i = 0; i < 5; i++) {

                  rooms.add(new Room(10 + i, RoomCategory.A));

                  rooms.add(new Room(20 + i, RoomCategory.B));

                  rooms.add(new Room(30 + i, RoomCategory.C));

                  rooms.add(new Room(40 + i, RoomCategory.D));

            }

      }

}

Niciun comentariu:

Trimiteți un comentariu