diff --git a/OOP/Java/Assignments/FISAC/Q8.java b/OOP/Java/Assignments/FISAC/Q8.java new file mode 100644 index 0000000..f830e3a --- /dev/null +++ b/OOP/Java/Assignments/FISAC/Q8.java @@ -0,0 +1,57 @@ +import java.util.*; + +class Movie { + String movieName, seatType; + int seatsAvailable; + + Movie(String movieName, String seatType, int seatsAvailable) { + this.movieName = movieName; + this.seatType = seatType; + this.seatsAvailable = seatsAvailable; + } +} + +class BharathCinemasMultiplex { + ArrayList movies = new ArrayList<>(); + ArrayList users = new ArrayList<>(); + + void addMovie(Movie movie) { + movies.add(movie); + } + + void listMovies() { + for (Movie m : movies) + System.out.println(m.movieName + " (" + m.seatType + ") - Seats: " + m.seatsAvailable); + } + + void bookTicket(String userName, String movieName, String seatType, int noOfTickets) { + for (Movie m : movies) { + if (m.movieName.equals(movieName) && m.seatType.equals(seatType)) { + if (m.seatsAvailable >= noOfTickets) { + m.seatsAvailable -= noOfTickets; + users.add(userName + " - " + movieName + " (" + seatType + ") - Tickets: " + noOfTickets); + System.out.println("Booking successful!"); + } else { + System.out.println("Not enough tickets available."); + } + return; + } + } + System.out.println("Movie not found."); + } + + void listUsers() { + for (String user : users) + System.out.println(user); + } + + public static void main(String[] args) { + BharathCinemasMultiplex bcm = new BharathCinemasMultiplex(); + bcm.addMovie(new Movie("Movie1", "Regular", 50)); + bcm.addMovie(new Movie("Movie2", "Premium", 30)); + bcm.listMovies(); + bcm.bookTicket("User1", "Movie1", "Regular", 2); + bcm.bookTicket("User2", "Movie2", "Premium", 5); + bcm.listUsers(); + } +}