mjain

Movie Booking system OOPS Design

Jul 24th, 2019
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.19 KB | None | 0 0
  1. package movieBookingSystem;
  2.  
  3. import java.sql.Array;
  4. import java.sql.Connection;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.util.Date;
  9. import java.util.HashMap;
  10. import java.util.List;
  11.  
  12. public class MovieBookingSystem {
  13.  
  14.     public enum BookingStatus {
  15.         REQUESTED, PENDING, CONFIRMED, CHECKED_IN, CANCELED, ABANDONED
  16.     }
  17.  
  18.     public enum SeatType {
  19.         REGULAR, PREMIUM, ACCESSIBLE, SHIPPED, EMERGENCY_EXIT, OTHER
  20.     }
  21.  
  22.     public enum AccountStatus {
  23.         ACTIVE, BLOCKED, BANNED, COMPROMISED, ARCHIVED, UNKNOWN
  24.     }
  25.  
  26.     public enum PaymentStatus {
  27.         UNPAID, PENDING, COMPLETED, FILLED, DECLINED, CANCELLED, ABANDONED, SETTLING, SETTLED, REFUNDED
  28.     }
  29.  
  30.     public class City {
  31.         String name;
  32.         String latitude;
  33.         String longitude;
  34.         String cityId;
  35.         String countryName;
  36.         String statename;
  37.     }
  38.     public class Address {
  39.         String street, landmark, state, city, country, pincode;
  40.     }
  41.     public class Cinema {
  42.         String           cityId;
  43.         String           cinemaId;
  44.         String           name;
  45.         Address          address;
  46.         List<CinemaHall> halls;
  47.     }
  48.  
  49.     public class CinemaHall {
  50.         String               name;
  51.         int                  totalNoOFSeat;
  52.         List<CinemaHallSeat> seatList;
  53.         private List<Show>   shows;
  54.     }
  55.     public class CinemaHallSeat {
  56.         String   seatRow;
  57.         String   seatColumn;
  58.         SeatType sType;
  59.     }
  60.  
  61.     public class ShowSeat extends CinemaHallSeat {
  62.         private int     showSeatId;
  63.         private boolean isReserved;
  64.         private double  price;
  65.     }
  66.  
  67.     public class Show {
  68.         private int        showId;
  69.         private Date       createdOn;
  70.         private Date       startTime;
  71.         private Date       endTime;
  72.         private CinemaHall playedAt;
  73.         private Movie      movie;
  74.     }
  75.  
  76.     public class Movie {
  77.         String name;
  78.         String genre;
  79.         String language;
  80.         double duration;
  81.         Date   releaseDate;
  82.         String description;
  83.         String country;
  84.         Admin  addedBy;
  85.     }
  86.  
  87.     public class Account {
  88.         String        name;
  89.         String        userName;
  90.         String        password;
  91.         Date          createdOn;
  92.         AccountStatus status;
  93.         String        email;
  94.         String        phoneNo;
  95.  
  96.     }
  97.     public class Admin extends Account {
  98.         // add movies
  99.         // delete movies
  100.  
  101.     }
  102.     public class FrontDeskExecutive extends Account {
  103.         // book tickets
  104.         // cancel tickets
  105.  
  106.     }
  107.  
  108.     public class Guest extends Account {
  109.         // register
  110.     }
  111.  
  112.     public class Booking {
  113.         String         bokingId;
  114.         Date           bookingTime;
  115.         BookingStatus  status;
  116.         int            noOfSeats;
  117.         List<ShowSeat> seats;
  118.         Show           show;
  119.         Payment        paymentData;
  120.         // make payment
  121.         // show payment
  122.         // show details
  123.         // cancel
  124.         // assignSeats
  125.  
  126.     }
  127.  
  128.     public class Payment {
  129.         double        amount;
  130.         String        payId;
  131.         Date          createdDate;
  132.         PaymentStatus staus;
  133.  
  134.     }
  135.  
  136.     // Search
  137.     public interface Search {
  138.         public List<Movie> searchByTitle(String title);
  139.  
  140.         public List<Movie> searchByLanguage(String language);
  141.  
  142.         public List<Movie> searchByGenre(String genre);
  143.  
  144.         public List<Movie> searchByReleaseDate(Date relDate);
  145.  
  146.         public List<Movie> searchByCity(String cityName);
  147.     }
  148.     public class Catalog implements Search {
  149.         HashMap<String, List<Movie>> movieTitles;
  150.         HashMap<String, List<Movie>> movieLanguages;
  151.         HashMap<String, List<Movie>> movieGenres;
  152.         HashMap<Date, List<Movie>>   movieReleaseDates;
  153.         HashMap<String, List<Movie>> movieCities;
  154.  
  155.         @Override
  156.         public List<Movie> searchByTitle(String title) {
  157.             // TODO Auto-generated method stub
  158.             return movieTitles.get(title);
  159.         }
  160.  
  161.         @Override
  162.         public List<Movie> searchByLanguage(String language) {
  163.             // TODO Auto-generated method stub
  164.             return null;
  165.         }
  166.  
  167.         @Override
  168.         public List<Movie> searchByGenre(String genre) {
  169.             // TODO Auto-generated method stub
  170.             return null;
  171.         }
  172.  
  173.         @Override
  174.         public List<Movie> searchByReleaseDate(Date relDate) {
  175.             // TODO Auto-generated method stub
  176.             return null;
  177.         }
  178.  
  179.         @Override
  180.         public List<Movie> searchByCity(String cityName) {
  181.             // TODO Auto-generated method stub
  182.             return null;
  183.         }
  184.  
  185.     }
  186.     // How to handle concurrency
  187.  
  188.     public class Customer extends Account {
  189.         // login,logout
  190.         // can search/selct moveiw
  191.         // can book,cancel
  192.         // apply voucher
  193.         public boolean makeBooking(Booking bookingData) throws SQLException {
  194.             List<ShowSeat> seats = bookingData.seats;
  195.             Integer seatIds[] = new Integer[seats.size()];
  196.             int index = 0;
  197.             for (ShowSeat seat : seats) {
  198.                 seatIds[index++] = seat.showSeatId;
  199.             }
  200.             Connection dbConnection = null;// get DBConnection here
  201.             dbConnection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
  202.  
  203.             String selectSQL = "Select * From ShowSeat where ShowID=? && ShowSeatID in (?) && isReserved=0";
  204.             PreparedStatement preparedStatement = dbConnection.prepareStatement(selectSQL);
  205.             preparedStatement.setInt(1, bookingData.show.showId);
  206.             Array array = dbConnection.createArrayOf("INTEGER", seatIds);
  207.             preparedStatement.setArray(2, array);
  208.  
  209.             ResultSet rs = preparedStatement.executeQuery();
  210.             // With TRANSACTION_SERIALIZABLE all the read rows will have the
  211.             // write lock, so we can
  212.             // safely assume that no one else is modifying them.
  213.             if (rs.next()) {
  214.                 rs.last(); // move to the last row, to calculate the row count
  215.                 int rowCount = rs.getRow();
  216.                 // check if we have expected number of rows, if not, this means
  217.                 // another process is
  218.                 // trying to process at least one of the same row, if that is
  219.                 // the case we
  220.                 // should not process this booking.
  221.                 if (rowCount == seats.size()) {
  222.                     // update ShowSeat table...
  223.                     // update Booking table ...
  224.                     dbConnection.commit();
  225.                     return true;
  226.                 }
  227.             }
  228.             return false;
  229.         }
  230.  
  231.     }
  232. }
Add Comment
Please, Sign In to add comment