A Metropolitan Hotel has 5 floors and 10 rooms in each floor. The names of the visitors are entered in a Double Dimensional Array (DDA) as M[5][10].The Hotel Manager wants to know from the "Enquiry" about the position of a visitor (i.e. floor number and room number) as soon as he enters the name of the visitor. Write a program in Java to perform the above task.
Answers
String m[5][10];
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<10;j++)
{
m[i][j]=br.readLine();
System.out.println("Floor"+i+"Room"+j+"Name:"+m[i][j]);
}
}
import java.util.Scanner;
public class HotelEnquiry
{
public void hotelEnquiry()
{
Scanner in = new Scanner(System.in);
String M[][] = new String[5][10];
int i = 0, j = 0;
for (i = 0; i < 5; i++)
{
System.out.println("Enter floor " + (i + 1)
+ " guest details:");
for (j = 0; j < 10; j++) {
System.out.print("Guest in room " +
(j + 1) + ": ");
M[i][j] = in.nextLine();
}
}
boolean found = false;
System.out.print("\nEnter guest name to search: ");
String guest = in.nextLine();
for (i = 0; i < 5; i++)
{
for (j = 0; j < 10; j++)
{
if (M[i][j].equals(guest))
{
found = true;
break;
}
}
if (found)
break;
}
if (found)
System.out.println(guest + " is in room number "
+ (j + 1) + " on floor number " + (i + 1));
else
System.out.println(guest +
" is not staying at this hotel");
}
}