57 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
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<Movie> movies = new ArrayList<>();
 | 
						|
    ArrayList<String> 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();
 | 
						|
    }
 | 
						|
}
 |