├── .idea ├── .gitignore ├── misc.xml ├── modules.xml └── libraries │ └── mysql_connector_j_9_3_0.xml ├── .gitignore ├── Hotel_Reservation_System.iml ├── README.md └── HotelReservationSystem └── HotelReservationSystem.java /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Environment-dependent path to Maven home directory 5 | /mavenHomeManager.xml 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/libraries/mysql_connector_j_9_3_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Hotel_Reservation_System.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hotel Reservation System 🏨 2 | Welcome to the Hotel Reservation System, a Java-based application for managing hotel reservations efficiently. Whether you're running a small hotel, this system simplifies the reservation process, enhances guest management, and keeps your business organized. 3 | 4 | ## Features 🌟 5 | - Reserve a Room: Easily make new reservations by providing guest details, room numbers, and contact information. 6 | 7 | - View Reservations: Get an overview of all current reservations, including guest names, room numbers, contact details, and reservation dates. 8 | 9 | - Edit Reservation Details: Update guest names, room numbers, and contact information for existing reservations. 10 | 11 | - Delete Reservations: Remove reservations that are no longer needed. 12 | 13 | ## Getting Started 🚀 14 | ### Prerequisites 15 | - Java Development Kit (JDK) 16 | - MySQL Database 17 | - MySQL Connector/J (Java) 18 | 19 | ### Setup 20 | 1. Clone this repository to your local machine: 21 | 22 | git clone https://github.com/Shubham-Bhoite/Hotel-Reservation-System.git 23 | 2. Configure your MySQL database settings in the HotelReservationSystem.java file: 24 | 25 | private static final String DB_URL = "jdbc:mysql://localhost:3306/hotel_db"; 26 | private static final String DB_USER = "your_username"; 27 | private static final String DB_PASSWORD = "your_password"; 28 | 29 | 4. Compile and run the application 30 | 31 | 5. Follow the on-screen menu options to use the system. 32 | 33 | ## Usage 📋 34 | - Upon running the application, you'll be presented with a menu to choose your desired operation (reservation, viewing, editing, or exiting). 35 | 36 | - Follow the prompts to input reservation details, view current reservations, edit existing bookings, and more. 37 | 38 | 39 | Happy booking! 🌆 40 | -------------------------------------------------------------------------------- /HotelReservationSystem/HotelReservationSystem.java: -------------------------------------------------------------------------------- 1 | import java.sql.DriverManager; 2 | import java.sql.SQLException; 3 | import java.sql.Connection; 4 | import java.util.Scanner; 5 | import java.sql.Statement; 6 | import java.sql.ResultSet; 7 | 8 | 9 | public class HotelReservationSystem { 10 | private static final String url = "jdbc:mysql://localhost:3306/hotel_db"; 11 | private static final String username = "root"; 12 | private static final String password = "root"; 13 | 14 | public static void main(String[] args) throws ClassNotFoundException, SQLException{ 15 | try{ 16 | Class.forName("com.mysql.cj.jdbc.Driver"); 17 | }catch (ClassNotFoundException e){ 18 | System.out.println(e.getMessage()); 19 | } 20 | 21 | try{ 22 | Connection connection = DriverManager.getConnection(url, username, password); 23 | while(true){ 24 | System.out.println(); 25 | System.out.println("HOTEL MANAGEMENT SYSTEM"); 26 | Scanner scanner = new Scanner(System.in); 27 | System.out.println("1. Reserve a room"); 28 | System.out.println("2. View Reservations"); 29 | System.out.println("3. Get Room Number"); 30 | System.out.println("4. Update Reservations"); 31 | System.out.println("5. Delete Reservations"); 32 | System.out.println("0. Exit"); 33 | System.out.print("Choose an option: "); 34 | int choice = scanner.nextInt(); 35 | switch (choice) { 36 | case 1: 37 | reserveRoom(connection, scanner); 38 | break; 39 | case 2: 40 | viewReservations(connection); 41 | break; 42 | case 3: 43 | getRoomNumber(connection, scanner); 44 | break; 45 | case 4: 46 | updateReservation(connection, scanner); 47 | break; 48 | case 5: 49 | deleteReservation(connection, scanner); 50 | break; 51 | case 0: 52 | exit(); 53 | scanner.close(); 54 | return; 55 | default: 56 | System.out.println("Invalid choice. Try again."); 57 | } 58 | } 59 | 60 | }catch (SQLException e){ 61 | System.out.println(e.getMessage()); 62 | } catch (InterruptedException e) { 63 | throw new RuntimeException(e); 64 | } 65 | 66 | 67 | } 68 | 69 | private static void reserveRoom(Connection connection, Scanner scanner) { 70 | try { 71 | System.out.print("Enter guest name: "); 72 | String guestName = scanner.next(); 73 | scanner.nextLine(); 74 | System.out.print("Enter room number: "); 75 | int roomNumber = scanner.nextInt(); 76 | System.out.print("Enter contact number: "); 77 | String contactNumber = scanner.next(); 78 | 79 | String sql = "INSERT INTO reservations (guest_name, room_number, contact_number) " + 80 | "VALUES ('" + guestName + "', " + roomNumber + ", '" + contactNumber + "')"; 81 | 82 | try (Statement statement = connection.createStatement()) { 83 | int affectedRows = statement.executeUpdate(sql); 84 | 85 | if (affectedRows > 0) { 86 | System.out.println("Reservation successful!"); 87 | } else { 88 | System.out.println("Reservation failed."); 89 | } 90 | } 91 | } catch (SQLException e) { 92 | e.printStackTrace(); 93 | } 94 | } 95 | 96 | private static void viewReservations(Connection connection) throws SQLException { 97 | String sql = "SELECT reservation_id, guest_name, room_number, contact_number, reservation_date FROM reservations"; 98 | 99 | try (Statement statement = connection.createStatement(); 100 | ResultSet resultSet = statement.executeQuery(sql)) { 101 | 102 | System.out.println("Current Reservations:"); 103 | System.out.println("+----------------+-----------------+---------------+----------------------+-------------------------+"); 104 | System.out.println("| Reservation ID | Guest | Room Number | Contact Number | Reservation Date |"); 105 | System.out.println("+----------------+-----------------+---------------+----------------------+-------------------------+"); 106 | 107 | while (resultSet.next()) { 108 | int reservationId = resultSet.getInt("reservation_id"); 109 | String guestName = resultSet.getString("guest_name"); 110 | int roomNumber = resultSet.getInt("room_number"); 111 | String contactNumber = resultSet.getString("contact_number"); 112 | String reservationDate = resultSet.getTimestamp("reservation_date").toString(); 113 | 114 | // Format and display the reservation data in a table-like format 115 | System.out.printf("| %-14d | %-15s | %-13d | %-20s | %-19s |\n", 116 | reservationId, guestName, roomNumber, contactNumber, reservationDate); 117 | } 118 | 119 | System.out.println("+----------------+-----------------+---------------+----------------------+-------------------------+"); 120 | } 121 | } 122 | 123 | 124 | private static void getRoomNumber(Connection connection, Scanner scanner) { 125 | try { 126 | System.out.print("Enter reservation ID: "); 127 | int reservationId = scanner.nextInt(); 128 | System.out.print("Enter guest name: "); 129 | String guestName = scanner.next(); 130 | 131 | String sql = "SELECT room_number FROM reservations " + 132 | "WHERE reservation_id = " + reservationId + 133 | " AND guest_name = '" + guestName + "'"; 134 | 135 | try (Statement statement = connection.createStatement(); 136 | ResultSet resultSet = statement.executeQuery(sql)) { 137 | 138 | if (resultSet.next()) { 139 | int roomNumber = resultSet.getInt("room_number"); 140 | System.out.println("Room number for Reservation ID " + reservationId + 141 | " and Guest " + guestName + " is: " + roomNumber); 142 | } else { 143 | System.out.println("Reservation not found for the given ID and guest name."); 144 | } 145 | } 146 | } catch (SQLException e) { 147 | e.printStackTrace(); 148 | } 149 | } 150 | private static void updateReservation(Connection connection, Scanner scanner) { 151 | try { 152 | System.out.print("Enter reservation ID to update: "); 153 | int reservationId = scanner.nextInt(); 154 | scanner.nextLine(); 155 | 156 | if (!reservationExists(connection, reservationId)) { 157 | System.out.println("Reservation not found for the given ID."); 158 | return; 159 | } 160 | 161 | System.out.print("Enter new guest name: "); 162 | String newGuestName = scanner.nextLine(); 163 | System.out.print("Enter new room number: "); 164 | int newRoomNumber = scanner.nextInt(); 165 | System.out.print("Enter new contact number: "); 166 | String newContactNumber = scanner.next(); 167 | 168 | String sql = "UPDATE reservations SET guest_name = '" + newGuestName + "', " + 169 | "room_number = " + newRoomNumber + ", " + 170 | "contact_number = '" + newContactNumber + "' " + 171 | "WHERE reservation_id = " + reservationId; 172 | 173 | try (Statement statement = connection.createStatement()) { 174 | int affectedRows = statement.executeUpdate(sql); 175 | 176 | if (affectedRows > 0) { 177 | System.out.println("Reservation updated successfully!"); 178 | } else { 179 | System.out.println("Reservation update failed."); 180 | } 181 | } 182 | } catch (SQLException e) { 183 | e.printStackTrace(); 184 | } 185 | } 186 | 187 | private static void deleteReservation(Connection connection, Scanner scanner) { 188 | try { 189 | System.out.print("Enter reservation ID to delete: "); 190 | int reservationId = scanner.nextInt(); 191 | 192 | if (!reservationExists(connection, reservationId)) { 193 | System.out.println("Reservation not found for the given ID."); 194 | return; 195 | } 196 | 197 | String sql = "DELETE FROM reservations WHERE reservation_id = " + reservationId; 198 | 199 | try (Statement statement = connection.createStatement()) { 200 | int affectedRows = statement.executeUpdate(sql); 201 | 202 | if (affectedRows > 0) { 203 | System.out.println("Reservation deleted successfully!"); 204 | } else { 205 | System.out.println("Reservation deletion failed."); 206 | } 207 | } 208 | } catch (SQLException e) { 209 | e.printStackTrace(); 210 | } 211 | } 212 | 213 | private static boolean reservationExists(Connection connection, int reservationId) { 214 | try { 215 | String sql = "SELECT reservation_id FROM reservations WHERE reservation_id = " + reservationId; 216 | 217 | try (Statement statement = connection.createStatement(); 218 | ResultSet resultSet = statement.executeQuery(sql)) { 219 | 220 | return resultSet.next(); 221 | } 222 | } catch (SQLException e) { 223 | e.printStackTrace(); 224 | return false; 225 | } 226 | } 227 | 228 | 229 | public static void exit() throws InterruptedException { 230 | System.out.print("Exiting System"); 231 | int i = 5; 232 | while(i!=0){ 233 | System.out.print("."); 234 | Thread.sleep(500); 235 | i--; 236 | } 237 | System.out.println(); 238 | System.out.println("ThankYou For Using Hotel Reservation System!!!"); 239 | 240 | } 241 | } --------------------------------------------------------------------------------