Pradeep
package hotel_management.com;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class UserProfile {
private String userID;
private String fullName;
private String email;
private String mobileNumber;
private String password;
private String role; // Admin or User
public UserProfile(String userID, String fullName, String email, String mobileNumber, String password, String role) {
this.userID = userID;
this.fullName = fullName;
this.email = email;
this.mobileNumber = mobileNumber;
this.password = password;
this.role = role;
}
// Getters and Setters
public String getUserID() { return userID; }
public void setUserID(String userID) { this.userID = userID; }
public String getFullName() { return fullName; }
public void setFullName(String fullName) { this.fullName = fullName; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
public String getMobileNumber() { return mobileNumber; }
public void setMobileNumber(String mobileNumber) { this.mobileNumber = mobileNumber; }
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
public String getRole() { return role; }
public void setRole(String role) { this.role = role; }
@Override
public String toString() {
return "UserProfile [UserID=" + userID + ", FullName=" + fullName + ", Email=" + email + ", MobileNumber=" + mobileNumber + ", Role=" + role + "]";
}
}
class Reservation {
private int reservationId;
private String checkInDate;
private String checkOutDate;
private String roomPreference;
private String guestName;
private long contactNumber;
public Reservation(int reservationId, String checkInDate, String checkOutDate, String roomPreference, String guestName, long contactNumber) {
this.reservationId = reservationId;
this.checkInDate = checkInDate;
this.checkOutDate = checkOutDate;
this.roomPreference = roomPreference;
this.guestName = guestName;
this.contactNumber = contactNumber;
}
@Override
public String toString() {
return "Reservation [ReservationId=" + reservationId + ", CheckIn=" + checkInDate + ", CheckOut=" + checkOutDate +
", RoomPreference=" + roomPreference + ", Guest=" + guestName + ", Contact=" + contactNumber + "]";
}
public int getReservationId() {
return reservationId;
}
public String getCheckin() {
return checkInDate;
}
public String getCheckout() {
return checkOutDate;
}
}
class BookingHistory {
private String userName;
private int reservationId;
public BookingHistory(String userName, int reservationId) {
this.userName = userName;
this.reservationId = reservationId;
}
@Override
public String toString() {
return "BookingHistory [User=" + userName + ", ReservationID=" + reservationId + "]";
}
public int getReservationId() {
return reservationId;
}
}
class Complaint {
private String userName;
private long contactNumber;
private int roomNumber;
private String typeOfComplaint;
private int feedbackRating;
public Complaint(String userName, long contactNumber, int roomNumber, String typeOfComplaint, int feedbackRating) {
this.userName = userName;
this.contactNumber = contactNumber;
this.roomNumber = roomNumber;
this.typeOfComplaint = typeOfComplaint;
this.feedbackRating = feedbackRating;
}
@Override
public String toString() {
return "Complaint [User=" + userName + ", Contact=" + contactNumber + ", Room=" + roomNumber +
", ComplaintType=" + typeOfComplaint + ", Rating=" + feedbackRating + "]";
}
public int getRoomNumber() {
return roomNumber;
}
}
class BookingHotel {
private int bookingID;
private String roomTypeSelection;
private String bookingDetails;
private double price;
// Constructor
public BookingHotel(int bookingID, String roomTypeSelection, String bookingDetails, double price) {
this.bookingID = bookingID;
this.roomTypeSelection = roomTypeSelection;
this.bookingDetails = bookingDetails;
this.price = price;
}
// Getters and Setters
public int getBookingID() { return bookingID; }
public void setRoomTypeSelection(String roomTypeSelection) { this.roomTypeSelection = roomTypeSelection; }
public String getRoomTypeSelection() { return roomTypeSelection; }
public String getBookingDetails() { return bookingDetails; }
public double getPrice() { return price; }
@Override
public String toString() {
return "BookingHotel [BookingID=" + bookingID + ", RoomTypeSelection=" + roomTypeSelection +
", BookingDetails=" + bookingDetails + ", Price=" + price + "]";
}
}
class Room {
private int roomid;
private String roomtype;
private String avail;
private double price;
public Room(int roomid, String roomtype, String avail, double price) {
this.roomid = roomid;
this.roomtype = roomtype;
this.avail = avail;
this.price = price;
}
public int getRoomid() {
return roomid;
}
public void setRoomid(int roomid) {
this.roomid = roomid;
}
public String getRoomtype() {
return roomtype;
}
public void setRoomtype(String roomtype) {
this.roomtype = roomtype;
}
public String getAvail() {
return avail;
}
public void setAvail(String avail) {
this.avail = avail;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return roomid + " " + roomtype + " " + avail + " " + price;
}
}
public class Main {
static List<UserProfile> userProfiles = new ArrayList<>();
static List<Reservation> reservations = new ArrayList<>();
static List<BookingHistory> bookingHistories = new ArrayList<>();
static List<Complaint> complaints = new ArrayList<>();
static List<BookingHotel> bookings = new ArrayList<>();
static List<Room> rooms = new ArrayList<>();
static int bookingCounter = 1; // Auto-incremented booking ID
static int reservationid = 1;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean exit = false;
// Initialize some rooms
rooms.add(new Room(101, "Single", "Available", 5000));
rooms.add(new Room(102, "Single", "Available", 5000));
rooms.add(new Room(103, "Single", "Available", 5000));
rooms.add(new Room(104, "Double", "Available", 3000));
rooms.add(new Room(105, "Double", "Available", 3000));
rooms.add(new Room(106, "Double", "Available", 3000));
rooms.add(new Room(107, "Single", "Available", 5000));
while (!exit) {
System.out.println("----- Hotel Management System -----");
System.out.println("1. Register User");
System.out.println("2. Login");
System.out.println("3. Exit");
System.out.print("Choose an option: ");
int option = sc.nextInt();
switch (option) {
case 1:
registerUser(sc); // Register a user
break;
case 2:
login(sc); // Login for Admin or User
break;
case 3:
exit = true;
System.out.println("Exiting System. Thank you!");
break;
default:
System.out.println("Invalid option. Please try again.");
break;
}
}
}
public static void registerUser(Scanner sc) {
System.out.println("---- Register User ----");
System.out.print("Enter User ID: ");
String userID = sc.next();
// Validate User ID
if (userID.trim().isEmpty()) {
System.out.println("Invalid input for User ID. Please try again.");
return;
}
System.out.print("Enter Full Name: ");
sc.nextLine(); // Consume newline
String fullName = sc.nextLine();
if (fullName.trim().isEmpty()) {
System.out.println("Invalid input for Full Name. Please try again.");
return;
}
System.out.print("Enter Email: ");
String email = sc.next();
if (email.trim().isEmpty()) {
System.out.println("Invalid input for Email. Please try again.");
return;
}
System.out.print("Enter Mobile Number: ");
String mobileNumber = sc.next();
if (mobileNumber.trim().isEmpty()) {
System.out.println("Invalid input for Mobile Number. Please try again.");
return;
}
System.out.print("Enter Password: ");
String password = sc.next();
if (password.trim().isEmpty()) {
System.out.println("Invalid input for Password. Please try again.");
return;
}
System.out.print("Enter Role (admin/user): ");
String role = sc.next();
if (!(role.equalsIgnoreCase("admin") || role.equalsIgnoreCase("user"))) {
System.out.println("Invalid role. Please select either admin or user.");
return;
}
UserProfile userProfile = new UserProfile(userID, fullName, email, mobileNumber, password, role);
userProfiles.add(userProfile);
System.out.println("User registered successfully!");
}
public static void login(Scanner sc) {
System.out.println("---- Login ----");
System.out.print("Enter User ID: ");
String userID = sc.next();
System.out.print("Enter Password: ");
String password = sc.next();
for (UserProfile userProfile : userProfiles) {
if (userProfile.getUserID().equals(userID) && userProfile.getPassword().equals(password)) {
System.out.println("Login successful!");
if (userProfile.getRole().equalsIgnoreCase("admin")) {
adminPage(sc); // Admin page
} else {
userPage(sc); // User page
}
return;
}
}
System.out.println("Invalid UserID or Password.");
}
public static void adminPage(Scanner sc) {
boolean exit = false;
while (!exit) {
System.out.println("----- Admin Page -----");
System.out.println("1. Booking Hotel Services");
System.out.println("2. View Booking History");
System.out.println("3. View Booking History by ID");
System.out.println("4. View Room Status");
System.out.println("5. View Check-out Billing Invoice");
System.out.println("6. View Complaints");
System.out.println("7. Logout");
System.out.print("Choose an option: ");
int option = sc.nextInt();
switch (option) {
case 1:
bookHotelServices(sc); // Book hotel services
break;
case 2:
viewBookingHistoryAdmin(); // View booking history for admin
break;
case 3:
viewBookingHistoryByID(sc); // View booking history by ID
break;
case 4:
viewRoomStatus(); // View room status
break;
case 5:
viewCheckOutBillingInvoice(sc); // View check-out billing invoice
break;
case 6:
viewComplaints(); // View complaints
break;
case 7:
exit = true;
System.out.println("Logged out from Admin Page.");
break;
default:
System.out.println("Invalid option. Please try again.");
break;
}
}
}
public static void userPage(Scanner sc) {
boolean exit = false;
while (!exit) {
System.out.println("----- User Page -----");
System.out.println("1. Make Reservation");
System.out.println("2. View Booking History");
System.out.println("3. View Room Status");
System.out.println("4. Check-out Billing");
System.out.println("5. Make Complaint");
System.out.println("6. Contact");
System.out.println("7. Pay Bill");
System.out.println("8. Logout");
System.out.print("Choose an option: ");
int option = sc.nextInt();
switch (option) {
case 1:
makeReservation(sc); // Make reservation
break;
case 2:
viewBookingHistory(); // View booking history
break;
case 3:
viewRoomStatus(); // View room status
break;
case 4:
checkOutBilling(sc); // Check-out billing
break;
case 5:
makeComplaint(sc); // Make complaint
break;
case 6:
contact(); // Contact information
break;
case 7:
payBill(sc); // Call the bill payment method
break;
case 8:
exit = true;
System.out.println("Logged out from User Page.");
break;
default:
System.out.println("Invalid option. Please try again.");
break;
}
}
}
// User Story 4: Make reservation
public static void updateroomstatus(int id) {
for (Room details : rooms) {
if (details.getRoomid() == id) {
details.setAvail("Booked");
}
}
}
public static void roomSetter(int id) {
for (Room details : rooms) {
if (details.getRoomid() == id) {
details.setAvail("Available");
}
}
}
public static boolean isRoomAvailable(int id) {
for (Room room : rooms) {
if (room.getRoomid() == id && room.getAvail().equalsIgnoreCase("Available")) {
return true;
}
}
return false;
}
public static void makeReservation(Scanner sc) {
viewRoomStatus();
System.out.println("---- Make Reservation ----");
System.out.print("Enter Room ID: ");
int id = sc.nextInt();
// Validate Room ID
boolean roomExists = false;
for (Room room : rooms) {
if (room.getRoomid() == id) {
roomExists = true;
break;
}
}
if (!roomExists) {
System.out.println("Invalid Room ID. Please choose a valid room.");
return;
}
// Check if room is available
if (!isRoomAvailable(id)) {
System.out.println("Room is already booked. Please select a different room.");
return;
}
updateroomstatus(id);
System.out.println("Reservation ID: " + reservationid);
int reservationId = reservationid;
reservationid++; // Increment reservation ID for next reservation
System.out.print("Enter Check-In Date (YYYY-MM-DD): ");
String checkInDate = sc.next();
System.out.print("Enter Check-Out Date (YYYY-MM-DD): ");
String checkOutDate = sc.next();
System.out.print("Enter Room Preference (Single/Double): ");
String roomPreference = sc.next();
System.out.print("Enter Guest Name: ");
sc.nextLine(); // Consume newline
String guestName = sc.nextLine();
System.out.print("Enter Contact Number: ");
long contactNumber = sc.nextLong();
Reservation reservation = new Reservation(reservationId, checkInDate, checkOutDate, roomPreference, guestName, contactNumber);
reservations.add(reservation);
BookingHistory bookingHistory = new BookingHistory(guestName, reservationId);
bookingHistories.add(bookingHistory);
System.out.println("Reservation Successful!");
}
// User Story 5: View booking history
public static void viewBookingHistory() {
System.out.println("---- Booking History ----");
for (BookingHistory history : bookingHistories) {
System.out.println(history);
}
}
// User Story 6: Make complaint
public static void makeComplaint(Scanner sc) {
System.out.println("---- Make Complaint ----");
System.out.print("Enter Your Name: ");
sc.nextLine(); // Consume newline
String userName = sc.nextLine();
System.out.print("Enter Contact Number: ");
long contactNumber = sc.nextLong();
System.out.print("Enter Room Number: ");
int roomNumber = sc.nextInt();
System.out.print("Enter Type of Complaint (Poor_housekeeping, Noisy_guests, etc.): ");
String typeOfComplaint = sc.next();
sc.nextLine();
System.out.print("Enter Feedback Rating (1-5): ");
int feedbackRating = sc.nextInt();
// Validate feedback rating
if (feedbackRating < 1 || feedbackRating > 5) {
System.out.println("Invalid feedback rating. Please enter a rating between 1 and 5.");
return;
}
Complaint complaint = new Complaint(userName, contactNumber, roomNumber, typeOfComplaint, feedbackRating);
complaints.add(complaint);
System.out.println("Complaint submitted successfully!");
}
// User Story 7: Contact
public static void contact() {
System.out.println("---- Contact Us ----");
System.out.println("For any inquiries, please contact us at:");
System.out.println("Email: [email protected]");
System.out.println("Phone: +123456789");
}
// User Story 8: View room status
public static void viewRoomStatus() {
System.out.println("---- Room Status ----");
System.out.println("Room Id Room Type Availability Price");
for (Room details : rooms) {
System.out.println(details.toString());
}
}
// User Story 9: Check-out billing
public static Room returnobject(int id) {
for (Room ro : rooms) {
if (ro.getRoomid() == id) {
return ro;
}
}
return null;
}
public static Reservation getdetails(int reservationid) {
for (Reservation res : reservations) {
if (res.getReservationId() == reservationid) {
return res;
}
}
return null;
}
public static void checkOutBilling(Scanner sc) {
System.out.println("---- Check-out Billing ----");
System.out.print("Enter Reservation ID: ");
int r_id = sc.nextInt();
Reservation res = getdetails(r_id);
if (res == null) {
System.out.println("Invalid Reservation ID.");
return;
}
System.out.print("Enter Room ID: ");
int id = sc.nextInt();
Room room = returnobject(id);
if (room == null) {
System.out.println("Invalid Room ID.");
return;
}
System.out.println("Room ID: " + id);
System.out.println("Room Type: " + room.getRoomtype());
System.out.println("Check-in Date: " + res.getCheckin());
System.out.println("Check-out Date: " + res.getCheckout());
System.out.print("Enter number of days: ");
int days = sc.nextInt();
double totalAmount = room.getPrice() * days;
System.out.println("Total Amount: $" + totalAmount);
System.out.println("1. PayBill");
System.out.println("2. Cancel");
int ch=sc.nextInt();
switch(ch) {
case 1:
{
payBill(sc);
roomSetter(id); // Set room as available
break;
}
case 2:{
userPage(sc);
break;
}
default:
System.out.println("Invalid option. Please try again.");
break;
}
}
// User Story 10: Bill Payment
public static void payBill(Scanner sc) {
System.out.println("---- Bill Payment ----");
// For simplicity, let's assume the service amount is fixed
double serviceAmount = 500.0;
System.out.println("Service Amount: $" + serviceAmount);
System.out.println("Select Payment Method: ");
System.out.println("1. Debit Card");
System.out.println("2. Credit Card");
int paymentOption = sc.nextInt();
if (paymentOption == 1 || paymentOption == 2) {
sc.nextLine(); // Consume newline
System.out.print("Enter Card Holder Name: ");
String cardHolderName = sc.nextLine();
System.out.print("Enter Card Number: ");
String cardNumber = sc.nextLine();
if (cardNumber.length() != 16) {
System.out.println("Invalid Card Number. It must be 16 digits.");
return;
}
System.out.print("Enter CVV: ");
String cvv = sc.nextLine();
if (cvv.length() != 3) {
System.out.println("Invalid CVV. Please try again.");
return;
}
System.out.print("Enter Expiry Date (MM/YY): ");
String expiryDate = sc.nextLine();
// Simulate payment processing
System.out.println("Processing payment...");
// Payment successful
System.out.println("Payment Successful!");
// Display invoice
System.out.println("---- Payment Invoice ----");
System.out.println("Card Holder Name: " + cardHolderName);
System.out.println("Service Amount: $" + serviceAmount);
System.out.println("Payment Method: " + (paymentOption == 1 ? "Debit Card" : "Credit Card"));
System.out.println("Card Number: **** **** **** " + cardNumber.substring(cardNumber.length() - 4));
System.out.println("Transaction Status: Successful");
System.out.println("------");
} else {
System.out.println("Invalid Payment Option.");
}
}
// User Story 11: Book hotel services (Admin)
// - Add new Booking -
public static void addBooking(Scanner sc) {
System.out.println("---- Add New Booking ----");
// Auto-generate Booking ID
int bookingID = bookingCounter++;
// Input Room Type Selection
System.out.print("Enter Room Type (Single/Double): ");
String roomTypeSelection = sc.next();
// Validate Room Type
if (!roomTypeSelection.equalsIgnoreCase("Single") && !roomTypeSelection.equalsIgnoreCase("Double")) {
System.out.println("Invalid Room Type. Please enter Single or Double.");
return;
}
// Input Booking Details
System.out.print("Enter Booking Details: ");
sc.nextLine(); // Consume newline
String bookingDetails = sc.nextLine();
// Input Price
System.out.print("Enter Price: ");
double price = sc.nextDouble();
// Create a new booking and add it to the list
BookingHotel booking = new BookingHotel(bookingID, roomTypeSelection, bookingDetails, price);
bookings.add(booking);
// Display success message
System.out.println("Successfully registered Booking: " + bookingID);
}
// - Update Booking -
public static void updateBooking(Scanner sc) {
System.out.println("---- Update Booking ----");
// Input Booking ID to update
System.out.print("Enter Booking ID to update: ");
int bookingID = sc.nextInt();
// Find the booking
for (BookingHotel booking : bookings) {
if (booking.getBookingID() == bookingID) {
// Input new Room Type
System.out.print("Enter new Room Type (Single/Double): ");
String newRoomType = sc.next();
// Validate Room Type
if (!newRoomType.equalsIgnoreCase("Single") && !newRoomType.equalsIgnoreCase("Double")) {
System.out.println("Invalid Room Type. Please enter Single or Double.");
return;
}
// Update Room Type
booking.setRoomTypeSelection(newRoomType);
System.out.println("Booking details are updated for Booking ID: " + bookingID);
return;
}
}
// If booking not found
System.out.println("Booking ID not found.");
}
// - Delete Booking -
public static void deleteBooking(Scanner sc) {
System.out.println("---- Delete Booking ----");
// Input Booking ID to delete
System.out.print("Enter Booking ID to delete: ");
int bookingID = sc.nextInt();
// Find and remove the booking
for (int i = 0; i < bookings.size(); i++) {
if (bookings.get(i).getBookingID() == bookingID) {
bookings.remove(i);
System.out.println("Booking details are deleted for Booking ID: " + bookingID);
return;
}
}
// If booking not found
System.out.println("Booking ID not found.");
}
// Admin Menu Option 1: Booking Hotel Services
public static void bookHotelServices(Scanner sc) {
boolean exit = false;
while (!exit) {
System.out.println("----- Booking Services Menu -----");
System.out.println("1. Add New Booking");
System.out.println("2. Update Booking");
System.out.println("3. Delete Booking");
System.out.println("4. Back to Admin Page");
System.out.print("Choose an option: ");
int option = sc.nextInt();
switch (option) {
case 1:
addBooking(sc); // Call method to add booking
break;
case 2:
updateBooking(sc); // Call method to update booking
break;
case 3:
deleteBooking(sc); // Call method to delete booking
break;
case 4:
exit = true; // Exit to admin page
break;
default:
System.out.println("Invalid option. Please try again.");
break;
}
}
}
// User Story 13: View booking history (Admin)
public static void viewBookingHistoryAdmin() {
System.out.println("---- Booking History ----");
for (BookingHistory history : bookingHistories) {
System.out.println(history);
}
}
// User Story 14: View booking history by ID (Admin)
public static void viewBookingHistoryByID(Scanner sc) {
System.out.println("---- View Booking History by ID ----");
System.out.print("Enter Reservation ID: ");
int reservationId = sc.nextInt();
for (BookingHistory history : bookingHistories) {
if (history.getReservationId() == reservationId) {
System.out.println(history);
return;
}
}
System.out.println("No booking history found for the given ID.");
}
// User Story 15: View check-out billing invoice (Admin)
public static void viewCheckOutBillingInvoice(Scanner sc) {
System.out.println("---- Check-out Billing Invoice ----");
System.out.print("Enter Reservation ID: ");
int r_id = sc.nextInt();
Reservation res = getdetails(r_id);
if (res == null) {
System.out.println("Invalid Reservation ID.");
return;
}
System.out.print("Enter Room ID: ");
int id = sc.nextInt();
Room room = returnobject(id);
if (room == null) {
System.out.println("Invalid Room ID.");
return;
}
System.out.println("Room ID: " + id);
System.out.println("Room Type: " + room.getRoomtype());
System.out.println("Check-in Date: " + res.getCheckin());
System.out.println("Check-out Date: " + res.getCheckout());
System.out.print("Enter number of days: ");
int days = sc.nextInt();
double totalAmount = room.getPrice() * days;
System.out.println("Total Amount: $" + totalAmount);
}
// User Story 12: View complaints (Admin)
public static void viewComplaints() {
System.out.println("---- All Complaints ----");
for (Complaint complaint : complaints) {
System.out.println(complaint);
}
}
}