1

I'm just a student and I've been trying to create a program wherein I have to use objects as hotel rooms, and the problem is my output which is below:

    Enter the number of guests: 1
    Enter the desired type of room: 
    One vacant room found!

    Room Number: 404
    Room Type: King-sized
    Room Area: 50m²
    AC Machine: Wall-mounted 

My desired output is:

    Enter the number of guests: 1
    Enter the desired type of room: Single
   
    One vacant room found!

    Room Number: 401
    Room Type: Single
    Room Area: 37m²
    AC Machine: Wall-mounted (Panasonic)

So, in other words, the program is not letting me to enter the second input and just keeps going straight in the conditions/statements. What am I missing or where did I go wrong?

Here's my code (kindly disregard the objects and IF-statement if it has no correlation to the matters at all)

    Scanner scan = new Scanner(System.in);
    
    System.out.print("Enter the number of guests: ");
    int guestNos = scan.nextInt();
    
    System.out.print("Enter the desired type of room: ");
    String dRoomType = scan.nextLine();
    
    Room roomOne = new Room();
    roomOne.setData(401, "Single", 37, "Wall-mounted");
    
    Room roomTwo = new Room();
    roomTwo.setData(402, "Double", 45, "Wall-mounted");
    
    Room roomThree = new Room();
    roomThree.setData(403, "Triple", 65, "Wall-mounted");
    
    Room roomFour = new Room();
    roomFour.setData(404, "King-sized", 50, "Wall-mounted");
    
    if(guestNos == 1) {
        if(dRoomType.equals("Single")) {
            System.out.println("\n\nOne vacant room found!");
            roomOne.displayData();
        }else {
            System.out.println("\nOne vacant room found!");
            roomFour.displayData();
        }
        
    }else if(guestNos == 2 && dRoomType.equals("Double")) {
        System.out.println("\nOne vacant room found!");
        roomTwo.displayData();
        
    }else {
        System.out.println("\nOne vacant room found!");
        roomThree.displayData();
    
    }
    
    scan.close();

Thanks in advance for the benevolent responses

James Z
  • 12,209
  • 10
  • 24
  • 44

0 Answers0