Computer Applications
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.
Java
Java Arrays
38 Likes
Answer
import java.util.Scanner;
public class KboatHotelEnquiry
{
public static void main(String args[]) {
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");
}
}
Variable Description Table
Program Explanation
Output
Answered By
18 Likes
Related Questions
If arrays M and M + N are as shown below, write a program in Java to find the array N.
M = {{-1, 0, 2}, M + N = {{-6, 9, 4}, {-3, -1, 6}, {4, 5, 0}, {4, 3, -1}} {1, -2, -3}}
A Class Teacher wants to keep the records of 40 students of her class along with their names and marks obtained in English, Hindi, Maths, Science and Computer Science in a Double Dimensional Array (DDA) as M[40][5]. When the teacher enters the name of a student as an input, the program must display the name, marks obtained in the 5 subjects and the total. Write a program in Java to perform the task.
A double dimensional array is defined as N[4][4] to store numbers. Write a program to find the sum of all even numbers and product of all odd numbers of the elements stored in Double Dimensional Array (DDA).
Sample Input:12 10 15 17 30 11 32 71 17 14 29 31 41 33 40 51
Sample Output:
Sum of all even numbers: ……….
Product of all odd numbers: ……….A Departmental Shop has 5 stores and 6 departments. The monthly sale of the department is kept in the Double Dimensional Array (DDA) as m[5][6]. The Manager of the shop wants to know the total monthly sale of each store and each department at any time. Write a program to perform the given task.
(Hint: Number of stores as rows and Number of departments as columns.)