Hotel Booking System
This program models a hotel booking system.
Problem Statement
Write a Java program to model Room and Booking classes.
Source Code
| 1 | class Room { |
| 2 | int number; boolean booked=false; |
| 3 | Room(int n){ number=n; } |
| 4 | } |
| 5 | class Booking { |
| 6 | Room room; |
| 7 | Booking(Room r){ room=r; room.booked=true; } |
| 8 | void show(){ System.out.println("Room "+room.number+" booked"); } |
| 9 | } |
| 10 | public class HotelBooking { |
| 11 | public static void main(String[] args) { |
| 12 | System.out.println("Eduinq Hotel Booking"); |
| 13 | Room r=new Room(101); |
| 14 | Booking b=new Booking(r); |
| 15 | b.show(); |
| 16 | } |
| 17 | } |
Program Output
Eduinq Hotel Booking Room 101 booked
Explanation
Room models hotel room. - Booking associates room with reservation. - This demonstrates encapsulation and association in enterprise modeling. Conclusion: Shows how to model hotel booking system.