Back to All Events

Manage a movie theater


This is a Java project that allows the user to manage a movie theater. The project consists of four classes: Main, Venue, Theater, Seat,Movie, and Showtime.

The Main class contains the main method and is responsible for the user interface and interaction. It presents a menu with various options, such as adding and removing movies and showtimes, buying tickets, and viewing movie and seating information. The Main class also uses The Movie Database (TMDB) API to fetch movie details and populate the Movie objects.

The Theater class represents a movie theater. It has several attributes, including a list of Movie objects, a list of Showtime objects, and a two-dimensional array of Seat objects. The Theater class has several methods that allow the user to add, remove, and view movies, showtimes, and seating information. It also has methods that allow the user to buy tickets and find movies and showtimes by title, time, and date.

The Seat class represents a seat in a movie theater. It has several attributes, including the seat's row and column number, and a boolean indicating whether the seat is available or not.

The Seat class has several getter and setter methods that allow the user to access and modify these attributes.

The Movie class represents a movie. It has several attributes, including the movie's title, release year, director, duration, and genre. The Movie class has several getter and setter methods that allow the user to access and modify these attributes.The Showtime class represents a showtime for a movie in a movie theater. It has several attributes, including the Movie object for the movie, the showtime's time and date, and the ticket price. The Showtime class has several getter and setter methods that allow the user to access and modify these attributes.The Venue class is a simple class that represents a venue such as a theater, stadium, or arena. It has name and location attributes and corresponding get and set methods. It is intended to be used as a base class that other classes such as Theater can extend to inherit its attributes and methods.

Class diagrams for all the classes and the relationships among the classes

class diagrams for all the classes and the relationships among the classes

Main.java

package Main;

import Main.Movie;
import Main.Seat;
import Main.ShowTime;
import Main.Theater;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    private Scanner scanner = new Scanner(System.in);

    private final List<Movie> movieList = new ArrayList<>();
    static List<ShowTime> showTimeList = new ArrayList<>();

    private Theater theater = new Theater();
    private Seat[][] seats = new Seat[10][10];

    public Main() {
        theater.setSeats(seats);
        theater.setMovies(movieList);
        theater.setShowTimes(showTimeList);

        Movie movie1 = new Movie();
        movie1.setTitle("The Godfather");
        movie1.setDirectorName("Francis Ford Coppola");
        movie1.setMovieLength("175");
        movie1.setIssueYear("1972-03-14");
        movie1.setReview("Spanning the years 1945 to 1955, a chronicle of the fictional Italian-American Corleone crime family. When organized crime family patriarch, Vito Corleone barely survives an attempt on his life, his youngest son, Michael steps in to take care of the would-be killers, launching a campaign of bloody revenge.");
        movie1.setCategoryName("[Drama, Crime]");
        movie1.setRating(8.711);
        movie1.setNumber(17735);

        Movie movie2 = new Movie();
        movie2.setTitle("Avatar");
        movie2.setDirectorName("James Cameron");
        movie2.setMovieLength("162");
        movie2.setIssueYear("2009-12-15");
        movie2.setReview("In the 22nd century, a paraplegic Marine is dispatched to the moon Pandora on a unique mission, but becomes torn between following orders and protecting an alien civilization.");
        movie2.setCategoryName("[Action, Adventure, Fantasy, Science Fiction]");
        movie2.setRating(7.569);
        movie2.setNumber(28872);

        movieList.add(movie2);
        movieList.add(movie1);

        for (int i = 0; i < seats.length; i++) {
            for (int j = 0; j < seats[i].length; j++) {
                seats[i][j] = new Seat(0, i + 1, false);
            }
        }
    }

    public static void main(String[] args) {
        Main main = new Main();
        main.start();
    }


    public void start() {

        while (true) {

            System.out.println("Welcome to the LUT Kino at Yliopistonkatu!");

            System.out.println("1. Add a movie");
            System.out.println("2. Remove a movie");
            System.out.println("3. View a movie");
            System.out.println("4. View all movies");
            System.out.println("5. Add a showtime");
            System.out.println("6. Remove a showtime");
            System.out.println("7. View a showtime");
            System.out.println("8. View all showtimes");
            System.out.println("9. Buy a ticket");
            System.out.println("10. View seating");
            System.out.println("0. Exit");

            System.out.print("Enter your choice:");
            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    theater.addMovie(commonsEnterTheTitleOfTheMovie());
                    break;
                case 2:
                    theater.delMovie(commonsEnterTheTitleOfTheMovie());
                    break;
                case 3:
                    theater.lookMovie(commonsEnterTheTitleOfTheMovie());
                    break;
                case 4:
                    theater.showMovieList();
                    break;
                case 5:
                    theater.addShowtime(commonsEnterTheTitleOfTheMovie());
                    break;
                case 6:
                    theater.removeShowtimeMovieByMovieTitle(commonsEnterTheTitleOfTheMovie());
                    break;
                case 7:
                    theater.viewShowTimeByMovieTitle(commonsEnterTheTitleOfTheMovie());
                    break;
                case 8:
                    theater.showTimeList();
                    break;
                case 9:
                    theater.buyTickets(commonsEnterTheTitleOfTheMovie());
                    break;
                case 10:
                    theater.showBuyTicketsSatus(commonsEnterTheTitleOfTheMovie());
                    break;
                default:
                    System.exit(0);
            }
            System.out.println();
        }
    }

    public String commonsEnterTheTitleOfTheMovie(){

        System.out.print("Enter the title of the movie:");
        scanner.useDelimiter("\n");
        String title = scanner.next();
        return title;
    }


}

Movie.java

package Main;

import java.io.Serializable;

public class Movie implements Serializable {
    private String title;
    private String directorName;
    private String movieLength;
    private String categoryName;
    private String issueYear;
    private String review;
    private double rating;
    private Integer number;


    public Movie() {
    }

    public Movie(String title, String directorName, String movieLength, String categoryName, String issueYear, String review, double rating, Integer number) {
        this.title = title;
        this.directorName = directorName;
        this.movieLength = movieLength;
        this.categoryName = categoryName;
        this.issueYear = issueYear;
        this.review = review;
        this.rating = rating;
        this.number = number;
    }


    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDirectorName() {
        return directorName;
    }

    public void setDirectorName(String directorName) {
        this.directorName = directorName;
    }

    public String getMovieLength() {
        return movieLength;
    }

    public void setMovieLength(String movieLength) {
        this.movieLength = movieLength;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public String getIssueYear() {
        return issueYear;
    }

    public void setIssueYear(String issueYear) {
        this.issueYear = issueYear;
    }

    public String getReview() {
        return review;
    }

    public void setReview(String review) {
        this.review = review;
    }

    public double getRating() {
        return rating;
    }

    public void setRating(double rating) {
        this.rating = rating;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }
}

Seat.java

package Main;

import java.io.Serializable;


public class Seat implements Serializable {

    private Integer lineNumber;

    private Integer columnNumber;

    private boolean status = false;

    @Override
    public String toString() {
        return "Seat{" +
                "lineNumber=" + lineNumber +
                ", columnNumber=" + columnNumber +
                ", status=" + status +
                '}';
    }

    public Seat() {
    }

    public Seat(Integer lineNumber, Integer columnNumber, boolean status) {
        this.lineNumber = lineNumber;
        this.columnNumber = columnNumber;
        this.status = status;
    }

    public Integer getLineNumber() {
        return lineNumber;
    }

    public void setLineNumber(Integer lineNumber) {
        this.lineNumber = lineNumber;
    }

    public Integer getColumnNumber() {
        return columnNumber;
    }

    public void setColumnNumber(Integer columnNumber) {
        this.columnNumber = columnNumber;
    }

    public boolean getStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }
}

ShowTime.java

package Main;


public class ShowTime {

    private Movie movie;

    private String time;

    private String datetime;

    private double price;

    public ShowTime() {
    }

    public ShowTime(Movie movie, String time, String datetime, double price) {
        this.movie = movie;
        this.time = time;
        this.datetime = datetime;
        this.price = price;
    }

    public Movie getMovie() {
        return movie;
    }

    public void setMovie(Movie movie) {
        this.movie = movie;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getDatetime() {
        return datetime;
    }

    public void setDatetime(String datetime) {
        this.datetime = datetime;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}

Theater.java

package Main;

import java.util.*;


public class Theater extends Venues {

    private final Scanner scanner = new Scanner(System.in);

    private List<Movie> movies;
    private List<ShowTime> showTimes;
    private Seat[][] seats;


    public Theater() {

    }

    public Theater(String name, String location, List<Movie> movies, List<ShowTime> showTimes, Seat[][] seats) {
        super(name, location);
        this.movies = movies;
        this.showTimes = showTimes;
        this.seats = seats;
    }

    public Theater(List<Movie> movies, List<ShowTime> showTimes, Seat[][] seats) {
        this.movies = movies;
        this.showTimes = showTimes;
        this.seats = seats;
    }

    public List<Movie> getMovies() {
        return movies;
    }

    public void setMovies(List<Movie> movies) {
        this.movies = movies;
    }

    public List<ShowTime> getShowTimes() {
        return showTimes;
    }

    public void setShowTimes(List<ShowTime> showTimes) {
        this.showTimes = showTimes;
    }

    public Seat[][] getSeats() {
        return seats;
    }

    public void setSeats(Seat[][] seats) {
        this.seats = seats;
    }

    public void addMovie(String title) {
        Movie movie = new Movie();

        System.out.print("Enter the director:");
        scanner.useDelimiter("\n");
        String directorName = scanner.next();
        System.out.print("Enter the duration:");
        scanner.useDelimiter("\n");
        String movieLength = scanner.next();
        movie.setTitle(title);
        movie.setDirectorName(directorName);
        movie.setMovieLength(movieLength);

        movies.add(movie);
        System.out.println("Movie added successfully!");
    }

    public void delMovie(String title) {
        for (int i = 0; i < movies.size(); i++) {
            if (title.equals(movies.get(i).getTitle())) {
                movies.remove(i);
                break;
            }
        }
    }

    public void lookMovie(String title) {
        for (Movie movie : movies) {
            if (title.equals(movie.getTitle())) {
                System.out.println("Title:" + movie.getTitle());
                System.out.println("Director:" + movie.getDirectorName());
                System.out.println("Release Year:" + movie.getIssueYear());
                System.out.println("Review::" + movie.getReview());
                System.out.println("Genre:" + movie.getCategoryName());
                System.out.println("Duration:" + movie.getMovieLength());
                System.out.println("Rating:" + movie.getRating());
                System.out.println("Number of Ratings:" + movie.getNumber());
                break;
            }
        }
    }

    public void showMovieList() {
        for (Movie movie : movies) {
            System.out.println();
            System.out.println("Title:" + movie.getTitle());
            System.out.println("Director:" + movie.getDirectorName());
            System.out.println("Release Year:" + movie.getIssueYear());
            System.out.println("Review:" + movie.getReview());
            System.out.println("Genre:" + movie.getCategoryName());
            System.out.println("Duration:" + movie.getMovieLength());
            System.out.println("Rating:" + movie.getRating());
            System.out.println("Number of Ratings:" + movie.getNumber());
        }
    }

    public void addShowtime(String title) {
        ShowTime showTime = new ShowTime();

        for (Movie movie : movies) {

            if (title.equals(movie.getTitle())) {
                showTime.setMovie(movie);

                System.out.print("Enter the time of the showtime (e.g. 7:00 PM):");
                scanner.useDelimiter("\n");
                String datetime = scanner.next();
                System.out.print("Enter the date of the showtime (e.g. 2022-12-15):");
                String time = scanner.next();
                System.out.print("Enter the ticket price for the showtime:");
                double price = scanner.nextDouble();

                showTime.setTime(time);
                showTime.setDatetime(datetime);
                showTime.setPrice(price);

                showTimes.add(showTime);
                System.out.println("Showtime added successfully!");
                break;
            }
        }


    }


    public void removeShowtimeMovieByMovieTitle(String title) {
        for (int i = 0; i < showTimes.size(); i++) {
            if (title.equals(showTimes.get(i).getMovie().getTitle())) {
                showTimes.remove(i);
                System.out.println("successfully delete!");
                break;
            }
        }
    }


    public void viewShowTimeByMovieTitle(String title) {
        for (ShowTime showTime : showTimes) {
            if (title.equals(showTime.getMovie().getTitle())) {
                System.out.println("Movie: " + showTime.getMovie().getTitle());
                System.out.println("Time: " + showTime.getTime());
                System.out.println("Date: " + showTime.getDatetime());
                System.out.println("Price: " + showTime.getPrice());
                break;
            }
        }
    }

    public void showTimeList() {
        for (ShowTime showTime : showTimes) {
            System.out.println();
            System.out.println("Movie: " + showTime.getMovie().getTitle());
            System.out.println("Time: " + showTime.getTime());
            System.out.println("Date: " + showTime.getDatetime());
            System.out.println("Price: " + showTime.getPrice());
        }
    }


    public void buyTickets(String title) {

        System.out.print("Enter the time of the showtime (e.g. 7:00 PM):");
        scanner.useDelimiter("\n");
        String datetime = scanner.next();
        System.out.print("Enter the date of the showtime (e.g. 2022-12-15):");
        String time = scanner.next();

        System.out.print("Enter the seat (row and column):");
        scanner.useDelimiter("\n");
        String str = scanner.next();
        String[] strings = str.split(" ");
        String row = strings[0];
        String column = strings[1];


        if (!seats[Integer.parseInt(row) - 1][Integer.parseInt(column) - 1].getStatus()) {
            seats[Integer.parseInt(row) - 1][Integer.parseInt(column) - 1].setStatus(true);
            System.out.println("Ticket bought!");
        }

    }

    public void showBuyTicketsSatus(String title) {
        System.out.print("Enter the showtime (time):");
        scanner.useDelimiter("\n");
        String time = scanner.next();
        System.out.print("Enter the showtime (date):");
        String date = scanner.next();


        for (int i = 0; i < this.seats.length; i++) {
            for (int j = 0; j < this.seats[i].length; j++) {
                for (Seat[] seat : seats) {
                    int row = seat[j].getLineNumber() - 1;
                    int column = seat[j].getColumnNumber() - 1;
                    if (row == i && column == j) {
                        this.seats[i][j].setStatus(true);
                    }
                }
                System.out.print("[" + (this.seats[i][j].getStatus() ? "O" : "X") + "]" + " ");
            }
            System.out.println();
        }
    }


}

Venues.java

package Main;


public class Venues {

    private String name;
    private String location;

    public Venues() {
    }

    public Venues(String name, String location) {
        this.name = name;
        this.location = location;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }
}

output

Next
Next
October 23

A program about study register for a university