The main purpose of this system is to provide a efficient way for a customer to book hotels, flight, train and bus. Also it automates the processes and activities of a travel agency.
THIS ISSUE IS POSTED AS A COLLEGE ASSIGNMENT
I recommend applying the "Introduce Null Object" refactoring technique. In the HotelRentalSystem code, the NullOption class is used as a placeholder to represent the default case when an invalid menu option is chosen. By introducing a null object instead of creating a new instance of NullOption, you can simplify the code and eliminate the need for a separate class. This approach makes the code cleaner and reduces the complexity associated with handling null cases.
Refactored Code:
import java.util.Scanner;
class Hotel {
void guestProfile() {
System.out.println("Executing guestProfile");
}
void guestDestination() {
System.out.println("Executing guestDestination");
}
void guestPurchase() {
System.out.println("Executing guestPurchase");
}
void guestProfileView() {
System.out.println("Executing guestProfileView");
}
void guestExit() {
System.out.println("Executing guestExit");
}
}
public class HotelRentalSystem {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
HotelRentalSystem system = new HotelRentalSystem();
system.domesticHotelRental();
}
void domesticHotelRental() {
int choice, n = 1;
System.out.println("\t\t\t\t\t\t======================================================");
System.out.println("\t\t\t\t\t\t| ** HOTEL RENTAL AND ROOM BOOKING SYSTEM **");
System.out.println("\t\t\t\t\t\t******************************************************");
System.out.println("\t\t\t\t\t\t| 1. Profile Creation |");
System.out.println("\t\t\t\t\t\t| 2. Destination |");
System.out.println("\t\t\t\t\t\t| 3. Booking & Payment |");
System.out.println("\t\t\t\t\t\t| 4. View Profile |");
System.out.println("\t\t\t\t\t\t| 5. Exit |");
System.out.println("\t\t\t\t\t\t******************************************************");
System.out.println("Enter Your Choice: ");
choice = scan.nextInt();
Hotel hotel = new Hotel();
n += executeMenuOption(choice, n, hotel);
System.out.println("n: " + n); // Solo para verificar el resultado
}
private int executeMenuOption(int choice, int n, Hotel hotel) {
switch (choice) {
case 1:
hotel.guestProfile();
return 1;
case 2:
hotel.guestDestination();
return 1;
case 3:
hotel.guestPurchase();
return 1;
case 4:
hotel.guestProfileView();
return 1;
case 5:
hotel.guestExit();
return 0;
default:
return 0;
}
}
}
THIS ISSUE IS POSTED AS A COLLEGE ASSIGNMENT I recommend applying the "Introduce Null Object" refactoring technique. In the HotelRentalSystem code, the NullOption class is used as a placeholder to represent the default case when an invalid menu option is chosen. By introducing a null object instead of creating a new instance of NullOption, you can simplify the code and eliminate the need for a separate class. This approach makes the code cleaner and reduces the complexity associated with handling null cases. Refactored Code: