Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Test {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner s = new Scanner(System.in);
  8.  
  9. System.out.println("Enter number of rows in seating arrangment: ");
  10. int rowNo = s.nextInt();
  11.  
  12. String[][] seating = new String[rowNo][4];
  13. for (int i = 0; i < rowNo; i++) {
  14. for (int j = 0; j < 4; j++) {
  15. if (j == 0)
  16. seating[i][j] = "A";
  17. else if (j == 1)
  18. seating[i][j] = "B";
  19. else if (j == 2)
  20. seating[i][j] = "C";
  21. else
  22. seating[i][j] = "D";
  23. }
  24. }
  25.  
  26. // Extracted your printing into a method
  27. printSeating(seating);
  28.  
  29. String askUser = "Y";
  30. while (askUser.equalsIgnoreCase("Y")) {
  31. System.out.println("Chose your Seat ");
  32.  
  33. System.out.println("Enter the row ");
  34. int row = s.nextInt();
  35. // nextInt() only gets the int and doesn't consume the newline
  36. // so this consumes the newline
  37. s.nextLine();
  38.  
  39. System.out.println("Enter the column ");
  40. String col = s.nextLine();
  41.  
  42. if (col.equals("A"))
  43. seating[row - 1][0] = "X";
  44. else if (col.equals("B"))
  45. seating[row - 1][1] = "X";
  46. else if (col.equals("C"))
  47. seating[row - 1][2] = "X";
  48. else
  49. seating[row - 1][3] = "X";
  50.  
  51. System.out.println("Contnioe to choose seat [y -Yes | n-No] :");
  52. askUser = s.next();
  53. }
  54.  
  55. System.out.println("Find Seating");
  56. // Extracted your printing into a method
  57. printSeating(seating);
  58. }
  59.  
  60.  
  61. private static void printSeating(String[][] seating) {
  62. for (int i = 0; i < seating.length; i++) {
  63. // Don't print a newline, since you want to continue printing on this line
  64. System.out.print(i + 1);
  65. for (int j = 0; j < seating[i].length; j++) {
  66. // Don't print a newline, since you want to continue printing on this line
  67. System.out.print(" " + seating[i][j]);
  68. }
  69. // now you print a newline
  70. System.out.println();
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement