Advertisement
Guest User

Untitled

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