-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathArray.java
69 lines (60 loc) · 2.17 KB
/
Array.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.io.*;
import java.util.Scanner;
public class Array {
static Scanner input = new Scanner(System.in);
static String arrS[][] = new String[5][5];
static String cName[] = { "A", "B", "C", "D", "E" };
static int i, j; // Loop Control Variables
static void dispData() { // Method that will display the array content
for (i = 0; i < 5; ++i) {
for (j = 0; j < 5; ++j) {
System.out.print(arrS[i][j] + "\t");
}
System.out.println();
}
System.out.println();
}
static boolean chkData(String vData) { // Method that will check for reservation availability
for (i = 0; i < 5; ++i) {
for (j = 0; j < 5; ++j) {
if ((arrS[i][j]).equalsIgnoreCase(vData)) {
arrS[i][j] = "X";
return true;
}
}
}
return false;
}
static boolean chkFull() { // Method that will check if all reservations were occupied
for (i = 0; i < 5; ++i) {
for (j = 0; j < 5; ++j) {
if (!(arrS[i][j]).equals("X")) {
return false;
}
}
}
return true;
}
public static void main(String eds[]) throws IOException { // the MAIN method program
String inData = new String("");
for (i = 0; i < 5; ++i) { // Initialized array with constant data
for (j = 0; j < 5; ++j) {
arrS[i][j] = new String((i + 1) + cName[j]);
}
}
do { // Loop until user press X to exit
dispData();
if (chkFull()) {
System.out.println("Reservation is FULL");
inData = "X";
} else {
System.out.print("Enter Seat Reservation: ");
inData = input.next();
if (chkData(inData))
System.out.println("Reservation Successful!");
else
System.out.println("Occupied Seat!");
}
} while (!inData.equalsIgnoreCase("X"));
}
}