Advertisement
wildinfo

javaSample#byanonymous

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