Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Chapter7
- {
- static Scanner in = new Scanner(System.in);
- static int[][] seatingChart;
- public static void main(String[] args)
- {
- seatingChart = new int[][]
- {
- { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
- { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
- { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
- { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
- { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
- { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
- { 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 },
- { 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 },
- { 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 },
- };
- printSeats(seatingChart);
- char response = 'Y';
- while ((response == 'Y') || (response == 'y'))
- {
- System.out.print("Pick by Seat <s>, Price <p>, or Quit <q>: ");
- char choice = in.next().charAt(0);
- switch (choice)
- {
- case'S':case's':
- { sellSeatByNumber(seatingChart);
- break; }
- case'P':case'p':
- { sellSeatByPrice(seatingChart);
- break; }
- case'Q':case'q':
- { System.out.print("Thans, come again!");
- System.exit(0); }
- default:
- { System.out.println("Error: Invalid choice."); }
- }
- System.out.print("Would you like to reserve another seat (Y/N)?: ");
- response = in.next().charAt(0);
- }
- System.out.print("Thanks, come again!");
- }
- public static void printSeats(int seatingChart[][])
- {
- for(int i=0; i<seatingChart.length; i++)
- {
- for(int j=0; j<seatingChart[i].length; j++)
- {
- if (j>0)
- System.out.print("\t");
- System.out.print(seatingChart[i][j]);
- }
- System.out.println();
- }
- }
- public static void sellSeatByPrice(int seatingChart[][])
- {
- System.out.print("Please enter a price for the seat you would like to sit in: ");
- int price = in.nextInt();
- out: for (int i=0;i<9;i++)
- for (int j=0;j<10;j++)
- if (seatingChart[i][j]==price)
- { seatingChart[i][j]=0; break out; }
- printSeats(seatingChart);
- }
- public static void sellSeatByNumber(int seatingChart[][])
- {
- System.out.println("Enter a row, then enter a seat number.");
- System.out.print("What row would you like to sit in?:");
- int row = in.nextInt();
- row = Math.abs(row-9);
- System.out.print("What seat in that row would you like to sit in?:");
- int col = in.nextInt();
- col -= 1;
- if (seatingChart[row][col]!=0)
- {
- seatingChart[row][col] = 0;
- printSeats(seatingChart);
- System.out.println("Your seat has been reserved");
- }
- else { System.out.println("Seat's taken, pick a different one"); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement