Advertisement
C-Squared

Chapter 7 Project Again

Apr 1st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.45 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Chapter7
  4. {
  5.         static Scanner in = new Scanner(System.in);
  6.         static int[][] seatingChart;
  7.        
  8.         public static void main(String[] args)
  9.         {
  10.                 seatingChart = new int[][]
  11.                                 {
  12.                           { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
  13.                           { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
  14.                           { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
  15.                           { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
  16.                           { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
  17.                           { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
  18.                           { 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 },
  19.                           { 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 },
  20.                           { 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 },
  21.                           };
  22.                        printSeats(seatingChart);
  23.                        char response = 'Y';
  24.                        while ((response == 'Y') || (response == 'y'))
  25.                        {
  26.                        System.out.print("Pick by Seat <s>, Price <p>, or Quit <q>: ");
  27.                        char choice = in.next().charAt(0);
  28.                            switch (choice)
  29.                             {
  30.                                case'S':case's':
  31.                                { sellSeatByNumber(seatingChart);
  32.                                    break; }
  33.                                case'P':case'p':
  34.                                { sellSeatByPrice(seatingChart);
  35.                                    break; }
  36.                                case'Q':case'q':
  37.                                { System.out.print("Thans, come again!");
  38.                                    System.exit(0); }
  39.                                default:
  40.                                { System.out.println("Error: Invalid choice."); }
  41.                             }
  42.                            System.out.print("Would you like to reserve another seat (Y/N)?: ");
  43.                         response = in.next().charAt(0);
  44.                        }
  45.                        System.out.print("Thanks, come again!");
  46.                        }
  47.                  
  48.                    public static void printSeats(int seatingChart[][])
  49.                    {
  50.                        for(int i=0; i<seatingChart.length; i++)
  51.                        {
  52.                            for(int j=0; j<seatingChart[i].length; j++)
  53.                            {
  54.                                if (j>0)
  55.                                    System.out.print("\t");
  56.                                    System.out.print(seatingChart[i][j]);
  57.                            }
  58.                            System.out.println();
  59.                        }
  60.                    }
  61.                  
  62.                  
  63.                  
  64.                  
  65.                    public static void sellSeatByPrice(int seatingChart[][])
  66.                    {
  67.                            System.out.print("Please enter a price for the seat you would like to sit in: ");
  68.                            int price = in.nextInt();
  69.                            out: for (int i=0;i<9;i++)
  70.                              for (int j=0;j<10;j++)
  71.                                 if (seatingChart[i][j]==price)
  72.                                 { seatingChart[i][j]=0; break out; }
  73.                             printSeats(seatingChart);
  74.                  
  75.                    }
  76.                  
  77.                    public static void sellSeatByNumber(int seatingChart[][])
  78.                    {
  79.                        System.out.println("Enter a row, then enter a seat number.");
  80.                        System.out.print("What row would you like to sit in?:");
  81.                        int row = in.nextInt();
  82.                        row = Math.abs(row-9);
  83.                        System.out.print("What seat in that row would you like to sit in?:");
  84.                        int col = in.nextInt();
  85.                        col -= 1;
  86.                        if (seatingChart[row][col]!=0)
  87.                        {
  88.                            seatingChart[row][col] = 0;
  89.                            printSeats(seatingChart);
  90.                            System.out.println("Your seat has been reserved");
  91.                        }
  92.                        else { System.out.println("Seat's taken, pick a different one"); }
  93.                    }
  94.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement