Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.64 KB | None | 0 0
  1. //Lecture 7
  2. //Author: Roger Nordström s071410
  3.  
  4. import java.util.*;
  5. public class Cinema
  6. {
  7. public static void main (String[] args)
  8. {
  9. //Variables
  10. Scanner reader=new Scanner(System.in);
  11. String[][] seats=new String[5][6];
  12. int row, seat, input, tickets, count = 0;
  13. String menu = "Menu: "
  14. + "\n1: Reserve seats"
  15. + "\n2: View current seating"
  16. + "\n0: Quit program";
  17. //Assigns numbers to the seats.
  18. for (int i = 0; i<5; i++)
  19. {
  20. seats[i][0]=new String("1");
  21. seats[i][1]=new String("2");
  22. seats[i][2]=new String("3");
  23. seats[i][3]=new String("4");
  24. seats[i][4]=new String("5");
  25. seats[i][5]=new String("6");
  26. }
  27. do
  28. {
  29. //Asks the user what she wants to do
  30. System.out.println("\n"+menu);
  31. System.out.println("Input (1-2 or 0): ");
  32. input = Integer.parseInt(reader.next());
  33. reader.nextLine();
  34. switch(input)
  35. {
  36. case 1:
  37. //When all the 30 seats are booked, the program informs the user that the
  38. cinema is full.
  39. if(count == 30)
  40. {
  41. System.out.println("\nThe cinema is fully booked.");
  42. }
  43. //If there are seats available
  44. else
  45. {
  46. do
  47. {
  48. printArray(seats);
  49. System.out.print("\nHow many seats would you like to reserve?
  50. Press 0 to cancel. ");
  51. tickets = reader.nextInt();
  52. if(tickets>5)
  53. {
  54. System.out.println("The maximum number of seats per
  55. reservation is 5.");
  56. }
  57. if(tickets==0)
  58. {
  59. System.out.println("Cancelling the reservation.");
  60. break;
  61. }
  62. if(tickets<0)
  63. {
  64. System.out.println("The minimum number of seats per
  65. reservation is 1.");
  66. }
  67. //If there aren't enough seats available for the specific number
  68. of persons
  69. if(tickets>(30-count))
  70. {
  71. System.out.println("Unfortunately there are only
  72. "+(30-count)+" seats available.");
  73. }
  74. }
  75. while(tickets>5 || tickets<0 || tickets>(30-count));
  76. recommendSeats(tickets, seats);
  77. for(int j=0;j<tickets;j++)
  78. {
  79. do
  80. {
  81. //Asks the user on what row he would like to book a seat
  82. System.out.println("\nWhere would person number "+(j+1)+"
  83. like to sit?");
  84. do
  85. {
  86. System.out.print("Row: ");
  87. row=reader.nextInt();
  88. //If the user choses a nonexistent row
  89. if(row>5 || row<1)
  90. {
  91. System.out.println("Please choose a row between 1 and
  92. 5.");
  93. }
  94. }
  95. while(row>5 || row<1);
  96. //Asks what seat the user would like.
  97. do
  98. {
  99. System.out.print("Seat: ");
  100. seat=reader.nextInt();
  101. //If the user choses a nonexistent seat
  102. if(seat!=1 && seat!=2 && seat!=3 &&
  103. seat!=4 && seat!=5 && seat!=6)
  104. {
  105. System.out.println("Please choose a seat between 1
  106. and 6.");
  107. }
  108. }
  109. while(seat!=1 && seat!=2 && seat!=3 && seat!=4 && seat!=5 &&
  110. seat!=6);
  111. }
  112. while(row>5);
  113. //If the seat is already taken, it informs the user about it
  114. if(seats[row-1][seat-1].equals("X"))
  115. {
  116. System.out.println("\nThat seat is already reserved, please
  117. select another one.");
  118. j--;
  119. }
  120. //If the seat is free, the program books it and marks it as taken.
  121. else
  122. {
  123. seats[row-1][seat-1] = "X";
  124. count++;
  125. }
  126. }
  127. }
  128. break;
  129.  
  130. case 2:
  131. printArray(seats);
  132. break;
  133.  
  134. case 0:
  135. System.out.println("\nGood bye!");
  136. break;
  137. //Informs the user that the input is not valid
  138. default:
  139. System.out.println("Invalid input.");
  140. break;
  141. }
  142. }
  143. //Exits the program
  144. while(input != 0);
  145. }
  146. //This method prints the current seating situation
  147. public static void printArray(String[][] a)
  148. {
  149. //Prints the rows
  150. System.out.println();
  151. System.out.println("-SCREEN-");
  152. for(int i=0;i<5;i++)
  153. {
  154. System.out.print(i+1+" ");
  155. //Prints the seats
  156. for(int j=0;j<6;j++)
  157. {
  158. System.out.print(a[i][j]);
  159. }
  160. System.out.print(" ");
  161. System.out.println();
  162. }
  163. }
  164. //This method recommends the best seats available
  165. public static void recommendSeats(int tickets, String[][] seats)
  166. {
  167. //Variables
  168. int j;
  169. //When reserving 1 ticket
  170. if(tickets == 1)
  171. {
  172. //Checks in there are free seats on the 3rd row
  173. if(!seats[2][0].equals("X") || !seats[2][1].equals("X") ||
  174. !seats[2][2].equals("X") || !seats[2][3].equals("X") ||
  175. !seats[2][4].equals("X") || !seats[2][5].equals("X"))
  176. {
  177. j=2;
  178. //Checks what seats are available, starting from the middle
  179. if(!seats[j][3].equals("X"))
  180. {
  181. System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
  182. }
  183. else if(!seats[j][2].equals("X"))
  184. {
  185. System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
  186. }
  187. else if(!seats[j][4].equals("X"))
  188. {
  189. System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
  190. }
  191. else if(!seats[j][1].equals("X"))
  192. {
  193. System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
  194. }
  195. else if(!seats[j][5].equals("X"))
  196. {
  197. System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
  198. }
  199. else if(!seats[j][0].equals("X"))
  200. {
  201. System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
  202. }
  203. }
  204. //Checks in there are free seats on the 4th row
  205. else if(!seats[3][0].equals("X") || !seats[3][1].equals("X") ||
  206. !seats[3][2].equals("X") || !seats[3][3].equals("X") ||
  207. !seats[3][4].equals("X") || !seats[3][5].equals("X"))
  208. {
  209. j=3;
  210. if(!seats[j][3].equals("X"))
  211. {
  212. System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
  213. }
  214. else if(!seats[j][2].equals("X"))
  215. {
  216. System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
  217. }
  218. else if(!seats[j][4].equals("X"))
  219. {
  220. System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
  221. }
  222. else if(!seats[j][1].equals("X"))
  223. {
  224. System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
  225. }
  226. else if(!seats[j][5].equals("X"))
  227. {
  228. System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
  229. }
  230. else if(!seats[j][0].equals("X"))
  231. {
  232. System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
  233. }
  234. }
  235. //Checks in there are free seats on the 2th row, and so on
  236. else if(!seats[1][0].equals("X") || !seats[1][1].equals("X") ||
  237. !seats[1][2].equals("X") || !seats[1][3].equals("X") ||
  238. !seats[1][4].equals("X") || !seats[1][5].equals("X"))
  239. {
  240. j=1;
  241. if(!seats[j][3].equals("X"))
  242. {
  243. System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
  244. }
  245. else if(!seats[j][2].equals("X"))
  246. {
  247. System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
  248. }
  249. else if(!seats[j][4].equals("X"))
  250. {
  251. System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
  252. }
  253. else if(!seats[j][1].equals("X"))
  254. {
  255. System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
  256. }
  257. else if(!seats[j][5].equals("X"))
  258. {
  259. System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
  260. }
  261. else if(!seats[j][0].equals("X"))
  262. {
  263. System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
  264. }
  265. }
  266. else if(!seats[4][0].equals("X") || !seats[4][1].equals("X") ||
  267. !seats[4][2].equals("X") || !seats[4][3].equals("X") ||
  268. !seats[4][4].equals("X") || !seats[4][5].equals("X"))
  269. {
  270. j=4;
  271. if(!seats[j][3].equals("X"))
  272. {
  273. System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
  274. }
  275. else if(!seats[j][2].equals("X"))
  276. {
  277. System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
  278. }
  279. else if(!seats[j][4].equals("X"))
  280. {
  281. System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
  282. }
  283. else if(!seats[j][1].equals("X"))
  284. {
  285. System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
  286. }
  287. else if(!seats[j][5].equals("X"))
  288. {
  289. System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
  290. }
  291. else if(!seats[j][0].equals("X"))
  292. {
  293. System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
  294. }
  295. }
  296. else if(!seats[0][0].equals("X") || !seats[0][1].equals("X") ||
  297. !seats[0][2].equals("X") || !seats[0][3].equals("X") ||
  298. !seats[0][4].equals("X") || !seats[0][5].equals("X"))
  299. {
  300. j=0;
  301. if(!seats[j][3].equals("X"))
  302. {
  303. System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
  304. }
  305. else if(!seats[j][2].equals("X"))
  306. {
  307. System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
  308. }
  309. else if(!seats[j][4].equals("X"))
  310. {
  311. System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
  312. }
  313. else if(!seats[j][1].equals("X"))
  314. {
  315. System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
  316. }
  317. else if(!seats[j][5].equals("X"))
  318. {
  319. System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
  320. }
  321. else if(!seats[j][0].equals("X"))
  322. {
  323. System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
  324. }
  325. }
  326. }
  327. //When reserving 2 tickets
  328. if(tickets == 2)
  329. {
  330. if(!seats[2][0].equals("X") && !seats[2][1].equals("X") ||
  331. !seats[2][1].equals("X") && !seats[2][2].equals("X") ||
  332. !seats[2][2].equals("X") && !seats[2][3].equals("X") ||
  333. !seats[2][3].equals("X") && !seats[2][4].equals("X") ||
  334. !seats[2][4].equals("X") && !seats[2][5].equals("X"))
  335. {
  336. j=2;
  337. if(!seats[j][2].equals("X") && !seats[j][3].equals("X"))
  338. {
  339. System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
  340. 4.");
  341. }
  342. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
  343. {
  344. System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
  345. 5.");
  346. }
  347. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
  348. {
  349. System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
  350. 3.");
  351. }
  352. else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
  353. {
  354. System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
  355. 6.");
  356. }
  357. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
  358. {
  359. System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
  360. 2.");
  361. }
  362. }
  363. else if(!seats[3][0].equals("X") && !seats[3][1].equals("X") ||
  364. !seats[3][1].equals("X") && !seats[3][2].equals("X") ||
  365. !seats[3][2].equals("X") && !seats[3][3].equals("X") ||
  366. !seats[3][3].equals("X") && !seats[3][4].equals("X") ||
  367. !seats[3][4].equals("X") && !seats[3][5].equals("X"))
  368. {
  369. j=3;
  370. if(!seats[j][2].equals("X") && !seats[j][3].equals("X") )
  371. {
  372. System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
  373. 4.");
  374. }
  375. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
  376. {
  377. System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
  378. 5.");
  379. }
  380. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
  381. {
  382. System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
  383. 3.");
  384. }
  385. else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
  386. {
  387. System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
  388. 6.");
  389. }
  390. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
  391. {
  392. System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
  393. 2.");
  394. }
  395. }
  396. else if(!seats[1][0].equals("X") && !seats[1][1].equals("X") ||
  397. !seats[1][1].equals("X") && !seats[1][2].equals("X") ||
  398. !seats[1][2].equals("X") && !seats[1][3].equals("X") ||
  399. !seats[1][3].equals("X") && !seats[1][4].equals("X") ||
  400. !seats[1][4].equals("X") && !seats[1][5].equals("X"))
  401. {
  402. j=1;
  403. if(!seats[j][2].equals("X") && !seats[j][3].equals("X") )
  404. {
  405. System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
  406. 4.");
  407. }
  408. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
  409. {
  410. System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
  411. 5.");
  412. }
  413. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
  414. {
  415. System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
  416. 3.");
  417. }
  418. else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
  419. {
  420. System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
  421. 6.");
  422. }
  423. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
  424. {
  425. System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
  426. 2.");
  427. }
  428. }
  429. else if(!seats[4][0].equals("X") && !seats[4][1].equals("X") ||
  430. !seats[4][1].equals("X") && !seats[4][2].equals("X") ||
  431. !seats[4][2].equals("X") && !seats[4][3].equals("X") ||
  432. !seats[4][3].equals("X") && !seats[4][4].equals("X") ||
  433. !seats[4][4].equals("X") && !seats[4][5].equals("X"))
  434. {
  435. j=4;
  436. if(!seats[j][2].equals("X") && !seats[j][3].equals("X") )
  437. {
  438. System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
  439. 4.");
  440. }
  441. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
  442. {
  443. System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
  444. 5.");
  445. }
  446. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
  447. {
  448. System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
  449. 3.");
  450. }
  451. else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
  452. {
  453. System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
  454. 6.");
  455. }
  456. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
  457. {
  458. System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
  459. 2.");
  460. }
  461. }
  462. else if(!seats[0][0].equals("X") && !seats[0][1].equals("X") ||
  463. !seats[0][1].equals("X") && !seats[0][2].equals("X") ||
  464. !seats[0][2].equals("X") && !seats[0][3].equals("X") ||
  465. !seats[0][3].equals("X") && !seats[0][4].equals("X") ||
  466. !seats[0][4].equals("X") && !seats[0][5].equals("X"))
  467. {
  468. j=0;
  469. if(!seats[j][2].equals("X") && !seats[j][3].equals("X") )
  470. {
  471. System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
  472. 4.");
  473. }
  474. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
  475. {
  476. System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
  477. 5.");
  478. }
  479. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
  480. {
  481. System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
  482. 3.");
  483. }
  484. else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
  485. {
  486. System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
  487. 6.");
  488. }
  489. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
  490. {
  491. System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
  492. 2.");
  493. }
  494. }
  495. //If it is impossible to recommend seats next to each other
  496. else
  497. {
  498. System.out.println("Unfortunately you can't sit next to each other.");
  499. }
  500. }
  501. //When reserving 3 tickets
  502. if(tickets == 3)
  503. {
  504. if(!seats[2][0].equals("X") && !seats[2][1].equals("X") &&
  505. !seats[2][2].equals("X") ||
  506. !seats[2][1].equals("X") && !seats[2][2].equals("X") &&
  507. !seats[2][3].equals("X") ||
  508. !seats[2][2].equals("X") && !seats[2][3].equals("X") &&
  509. !seats[2][4].equals("X") ||
  510. !seats[2][3].equals("X") && !seats[2][4].equals("X") &&
  511. !seats[2][5].equals("X"))
  512. {
  513. j=2;
  514. if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  515. !seats[j][4].equals("X"))
  516. {
  517. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
  518. 5.");
  519. }
  520. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  521. !seats[j][3].equals("X"))
  522. {
  523. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
  524. 4.");
  525. }
  526. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
  527. !seats[j][5].equals("X"))
  528. {
  529. System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
  530. 6.");
  531. }
  532. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  533. !seats[j][2].equals("X"))
  534. {
  535. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
  536. 3.");
  537. }
  538. }
  539. else if(!seats[3][0].equals("X") && !seats[3][1].equals("X") &&
  540. !seats[3][2].equals("X") ||
  541. !seats[3][1].equals("X") && !seats[3][2].equals("X") &&
  542. !seats[3][3].equals("X") ||
  543. !seats[3][2].equals("X") && !seats[3][3].equals("X") &&
  544. !seats[3][4].equals("X") ||
  545. !seats[3][3].equals("X") && !seats[3][4].equals("X") &&
  546. !seats[3][5].equals("X"))
  547. {
  548. j=3;
  549. if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  550. !seats[j][4].equals("X"))
  551. {
  552. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
  553. 5.");
  554. }
  555. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  556. !seats[j][3].equals("X"))
  557. {
  558. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
  559. 4.");
  560. }
  561. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
  562. !seats[j][5].equals("X"))
  563. {
  564. System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
  565. 6.");
  566. }
  567. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  568. !seats[j][2].equals("X"))
  569. {
  570. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
  571. 3.");
  572. }
  573. }
  574. else if(!seats[1][0].equals("X") && !seats[1][1].equals("X") &&
  575. !seats[1][2].equals("X") ||
  576. !seats[1][1].equals("X") && !seats[1][2].equals("X") &&
  577. !seats[1][3].equals("X") ||
  578. !seats[1][2].equals("X") && !seats[1][3].equals("X") &&
  579. !seats[1][4].equals("X") ||
  580. !seats[1][3].equals("X") && !seats[1][4].equals("X") &&
  581. !seats[1][5].equals("X"))
  582. {
  583. j=1;
  584. if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  585. !seats[j][4].equals("X"))
  586. {
  587. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
  588. 5.");
  589. }
  590. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  591. !seats[j][3].equals("X"))
  592. {
  593. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
  594. 4.");
  595. }
  596. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
  597. !seats[j][5].equals("X"))
  598. {
  599. System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
  600. 6.");
  601. }
  602. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  603. !seats[j][2].equals("X"))
  604. {
  605. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
  606. 3.");
  607. }
  608. }
  609. else if(!seats[4][0].equals("X") && !seats[4][1].equals("X") &&
  610. !seats[4][2].equals("X") ||
  611. !seats[4][1].equals("X") && !seats[4][2].equals("X") &&
  612. !seats[4][3].equals("X") ||
  613. !seats[4][2].equals("X") && !seats[4][3].equals("X") &&
  614. !seats[4][4].equals("X") ||
  615. !seats[4][3].equals("X") && !seats[4][4].equals("X") &&
  616. !seats[4][5].equals("X"))
  617. {
  618. j=4;
  619. if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  620. !seats[j][4].equals("X"))
  621. {
  622. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
  623. 5.");
  624. }
  625. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  626. !seats[j][3].equals("X"))
  627. {
  628. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
  629. 4.");
  630. }
  631. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
  632. !seats[j][5].equals("X"))
  633. {
  634. System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
  635. 6.");
  636. }
  637. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  638. !seats[j][2].equals("X"))
  639. {
  640. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
  641. 3.");
  642. }
  643. }
  644. else if(!seats[0][0].equals("X") && !seats[0][1].equals("X") &&
  645. !seats[0][2].equals("X") ||
  646. !seats[0][1].equals("X") && !seats[0][2].equals("X") &&
  647. !seats[0][3].equals("X") ||
  648. !seats[0][2].equals("X") && !seats[0][3].equals("X") &&
  649. !seats[0][4].equals("X") ||
  650. !seats[0][3].equals("X") && !seats[0][4].equals("X") &&
  651. !seats[0][5].equals("X"))
  652. {
  653. j=0;
  654. if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  655. !seats[j][4].equals("X"))
  656. {
  657. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
  658. 5.");
  659. }
  660. else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  661. !seats[j][3].equals("X"))
  662. {
  663. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
  664. 4.");
  665. }
  666. else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
  667. !seats[j][5].equals("X"))
  668. {
  669. System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
  670. 6.");
  671. }
  672. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  673. !seats[j][2].equals("X"))
  674. {
  675. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
  676. 3.");
  677. }
  678. }
  679. else
  680. {
  681. System.out.println("Unfortunately you can't sit next to each other.");
  682. }
  683. }
  684. //When reserving 4 tickets
  685. if(tickets == 4)
  686. {
  687. if(!seats[2][0].equals("X") && !seats[2][1].equals("X") &&
  688. !seats[2][2].equals("X") && !seats[2][3].equals("X") ||
  689. !seats[2][1].equals("X") && !seats[2][2].equals("X") &&
  690. !seats[2][3].equals("X") && !seats[2][4].equals("X") ||
  691. !seats[2][2].equals("X") && !seats[2][3].equals("X") &&
  692. !seats[2][4].equals("X") && !seats[2][5].equals("X"))
  693. {
  694. j=2;
  695. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  696. !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  697. {
  698. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
  699. and 5.");
  700. }
  701. else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  702. !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  703. {
  704. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
  705. and 6.");
  706. }
  707. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  708. !seats[j][2].equals("X") && !seats[j][3].equals("X"))
  709. {
  710. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
  711. and 4.");
  712. }
  713. }
  714. else if(!seats[3][0].equals("X") && !seats[3][1].equals("X") &&
  715. !seats[3][2].equals("X") && !seats[3][3].equals("X") ||
  716. !seats[3][1].equals("X") && !seats[3][2].equals("X") &&
  717. !seats[3][3].equals("X") && !seats[3][4].equals("X") ||
  718. !seats[3][2].equals("X") && !seats[3][3].equals("X") &&
  719. !seats[3][4].equals("X") && !seats[3][5].equals("X"))
  720. {
  721. j=3;
  722. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  723. !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  724. {
  725. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
  726. and 5.");
  727. }
  728. else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  729. !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  730. {
  731. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
  732. and 6.");
  733. }
  734. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  735. !seats[j][2].equals("X") && !seats[j][3].equals("X"))
  736. {
  737. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
  738. and 4.");
  739. }
  740. }
  741. else if(!seats[1][0].equals("X") && !seats[1][1].equals("X") &&
  742. !seats[1][2].equals("X") && !seats[1][3].equals("X") ||
  743. !seats[1][1].equals("X") && !seats[1][2].equals("X") &&
  744. !seats[1][3].equals("X") && !seats[1][4].equals("X") ||
  745. !seats[1][2].equals("X") && !seats[1][3].equals("X") &&
  746. !seats[1][4].equals("X") && !seats[1][5].equals("X"))
  747. {
  748. j=1;
  749. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  750. !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  751. {
  752. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
  753. and 5.");
  754. }
  755. else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  756. !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  757. {
  758. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
  759. and 6.");
  760. }
  761. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  762. !seats[j][2].equals("X") && !seats[j][3].equals("X"))
  763. {
  764. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
  765. and 4.");
  766. }
  767. }
  768. else if(!seats[4][0].equals("X") && !seats[4][1].equals("X") &&
  769. !seats[4][2].equals("X") && !seats[4][3].equals("X") ||
  770. !seats[4][1].equals("X") && !seats[4][2].equals("X") &&
  771. !seats[4][3].equals("X") && !seats[4][4].equals("X") ||
  772. !seats[4][2].equals("X") && !seats[4][3].equals("X") &&
  773. !seats[4][4].equals("X") && !seats[4][5].equals("X"))
  774. {
  775. j=4;
  776. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  777. !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  778. {
  779. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
  780. and 5.");
  781. }
  782. else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  783. !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  784. {
  785. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
  786. and 6.");
  787. }
  788. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  789. !seats[j][2].equals("X") && !seats[j][3].equals("X"))
  790. {
  791. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
  792. and 4.");
  793. }
  794. }
  795. else if(!seats[0][0].equals("X") && !seats[0][1].equals("X") &&
  796. !seats[0][2].equals("X") && !seats[0][3].equals("X") ||
  797. !seats[0][1].equals("X") && !seats[0][2].equals("X") &&
  798. !seats[0][3].equals("X") && !seats[0][4].equals("X") ||
  799. !seats[0][2].equals("X") && !seats[0][3].equals("X") &&
  800. !seats[0][4].equals("X") && !seats[0][5].equals("X"))
  801. {
  802. j=0;
  803. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  804. !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  805. {
  806. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
  807. and 5.");
  808. }
  809. else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
  810. !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  811. {
  812. System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
  813. and 6.");
  814. }
  815. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  816. !seats[j][2].equals("X") && !seats[j][3].equals("X"))
  817. {
  818. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
  819. and 4.");
  820. }
  821. }
  822. else
  823. {
  824. System.out.println("Unfortunately you can't sit next to each other.");
  825. }
  826. }
  827. //When reserving 5 tickets
  828. if(tickets == 5)
  829. {
  830. if(!seats[2][0].equals("X") && !seats[2][1].equals("X") &&
  831. !seats[2][2].equals("X") && !seats[2][3].equals("X") && !seats[2][4].equals("X") ||
  832. !seats[2][1].equals("X") && !seats[2][2].equals("X") &&
  833. !seats[2][3].equals("X") && !seats[2][4].equals("X") && !seats[2][5].equals("X"))
  834. {
  835. j=2;
  836. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  837. !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  838. {
  839. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
  840. 5 and 6.");
  841. }
  842. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  843. !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  844. {
  845. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
  846. 4 and 5.");
  847. }
  848. }
  849. else if(!seats[3][0].equals("X") && !seats[3][1].equals("X") &&
  850. !seats[3][2].equals("X") && !seats[3][3].equals("X") && !seats[3][4].equals("X") ||
  851. !seats[3][1].equals("X") && !seats[3][2].equals("X") &&
  852. !seats[3][3].equals("X") && !seats[3][4].equals("X") && !seats[3][5].equals("X"))
  853. {
  854. j=3;
  855. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  856. !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  857. {
  858. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
  859. 5 and 6.");
  860. }
  861. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  862. !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  863. {
  864. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
  865. 4 and 5.");
  866. }
  867. }
  868. else if(!seats[1][0].equals("X") && !seats[1][1].equals("X") &&
  869. !seats[1][2].equals("X") && !seats[1][3].equals("X") && !seats[1][4].equals("X") ||
  870. !seats[1][1].equals("X") && !seats[1][2].equals("X") &&
  871. !seats[1][3].equals("X") && !seats[1][4].equals("X") && !seats[1][5].equals("X"))
  872. {
  873. j=1;
  874. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  875. !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  876. {
  877. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
  878. 5 and 6.");
  879. }
  880. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  881. !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  882. {
  883. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
  884. 4 and 5.");
  885. }
  886. }
  887. else if(!seats[4][0].equals("X") && !seats[4][1].equals("X") &&
  888. !seats[4][2].equals("X") && !seats[4][3].equals("X") && !seats[4][4].equals("X") ||
  889. !seats[4][1].equals("X") && !seats[4][2].equals("X") &&
  890. !seats[4][3].equals("X") && !seats[4][4].equals("X") && !seats[4][5].equals("X"))
  891. {
  892. j=4;
  893. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  894. !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  895. {
  896. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
  897. 5 and 6.");
  898. }
  899. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  900. !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  901. {
  902. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
  903. 4 and 5.");
  904. }
  905. }
  906. else if(!seats[0][0].equals("X") && !seats[0][1].equals("X") &&
  907. !seats[0][2].equals("X") && !seats[0][3].equals("X") && !seats[0][4].equals("X") ||
  908. !seats[0][1].equals("X") && !seats[0][2].equals("X") &&
  909. !seats[0][3].equals("X") && !seats[0][4].equals("X") && !seats[0][5].equals("X"))
  910. {
  911. j=0;
  912. if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
  913. !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
  914. {
  915. System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
  916. 5 and 6.");
  917. }
  918. else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
  919. !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
  920. {
  921. System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
  922. 4 and 5.");
  923. }
  924. }
  925. else
  926. {
  927. System.out.println("Unfortunately you can't sit next to each other.");
  928. }
  929. }
  930. }
  931. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement