Java电影管理系统 (期末作业,超详细哟,拿走不谢!!!)

该文章展示了一个用Java编写的电影管理系统的详细代码,包括添加、删除电影,查看单个及所有电影的功能。系统使用ArrayList存储Movie对象,并通过用户输入交互。Movie类包含了电影的基本信息如标题、类型、导演等。文章强调了这个项目作为巩固Java基础知识的实践价值。
摘要由CSDN通过智能技术生成

Java电影管理系统 (期末作业,超详细哟,拿走不谢!!!)

一、菜单展示

菜单有如下功能:

  1. Add a movie
  2. Remove a movie
  3. View a movie
  4. View all movies
  5. exit
    在这里插入图片描述
    下面展示一些 内联代码片
public static void showmenu() {
        String menuStr = "Welcome to the Movie Project at MySouil!\n" +
                "1. Add a movie\n" +
                "2. Remove a movie\n" +
                "3. View a movie\n" +
                "4. View all movies\n" +
                "5. exit";

        System.out.println(menuStr);
    }

二、新建电影

下面展示一些 内联代码片

public static void addMovie(Scanner scanner, ArrayList<Movie> movieArrayList) {
        System.out.print("Enter the movie title:");
        String title = scanner.nextLine();
        System.out.print("Enter the movie type:");
        String type = scanner.nextLine();
        System.out.print("Enter the movie director:");
        String director = scanner.nextLine();
        System.out.print("Enter the movie nation:");
        String nation = scanner.nextLine();
        System.out.print("Enter the movie duration:");
        int duration = scanner.nextInt();
        System.out.print("Enter the movie score:");
        double score = scanner.nextDouble();

        Movie movie = new Movie(title, type, director, nation, duration, score);
        movieArrayList.add(movie);
        System.out.println("Movie added successfully!");
    }

在这里插入图片描述

三、删除电影

public static void addMovie(Scanner scanner, ArrayList<Movie> movieArrayList) {
        System.out.print("Enter the movie title:");
        String title = scanner.nextLine();
        System.out.print("Enter the movie type:");
        String type = scanner.nextLine();
        System.out.print("Enter the movie director:");
        String director = scanner.nextLine();
        System.out.print("Enter the movie nation:");
        String nation = scanner.nextLine();
        System.out.print("Enter the movie duration:");
        int duration = scanner.nextInt();
        System.out.print("Enter the movie score:");
        double score = scanner.nextDouble();

        Movie movie = new Movie(title, type, director, nation, duration, score);
        movieArrayList.add(movie);
        System.out.println("Movie added successfully!");
    }

在这里插入图片描述

四、展示电影

public static void showMovie(Scanner scanner, ArrayList<Movie> movieArrayList) {
        System.out.print("Enter the show movie title:");
        String title = scanner.nextLine();

        for (Movie movie:movieArrayList) {
            if(movie.getTitle().equals(title)){
                System.out.println(movie);
                return;
            }
        }
        System.out.println("The title was not found!");
    }

在这里插入图片描述

五、展示所有电影

public static void showAllMovie(ArrayList<Movie> movieArrayList) {
        for (Movie movie:movieArrayList) {
            System.out.println(movie);
        }

    }

在这里插入图片描述

六、功能控制和退出

public static void execute() {
        Scanner scanner = new Scanner(System.in);
        ArrayList<Movie> movieArrayList = new ArrayList<>();
        while (true) {
            showmenu();
            System.out.print("Enter your choice:");
            String option = scanner.nextLine();
            switch (option) {
                case "1":
                    addMovie(scanner,movieArrayList);
                    continue;
                case "2":
                    removeMovie(scanner,movieArrayList);
                    continue;
                case "3":
                    showMovie(scanner,movieArrayList);
                    continue;
                case "4":
                    showAllMovie(movieArrayList);
                    continue;
                case "5":
                    System.out.println("success exit!");
                    System.exit(0);
                default:
                    System.out.println("option error");
            }
        }

    }

七、其它

public class Movie {
    String title; // 电影名
    String type; // 类型
    String director; // 导演
    String nation; // 国家
    int duration; // 时长
    Double score; // 评分
    List<ShowTime>showTimeList; // 上映时间列表

    public Movie(String title, String type, String director, String nation, int duration, Double score) {
        this.title = title;
        this.type = type;
        this.director = director;
        this.nation = nation;
        this.duration = duration;
        this.score = score;
    }

    public String getTitle() {
        return title;
    }

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

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    public String getNation() {
        return nation;
    }

    public void setNation(String nation) {
        this.nation = nation;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public Double getScore() {
        return score;
    }

    public void setScore(Double score) {
        this.score = score;
    }

    public List<ShowTime> getShowTimeList() {
        return showTimeList;
    }

    public void setShowTimeList(List<ShowTime> showTimeList) {
        this.showTimeList = showTimeList;
    }

    @Override
    public String toString() {
        return "Movie{" +
                "title='" + title + '\'' +
                ", type='" + type + '\'' +
                ", director='" + director + '\'' +
                ", nation='" + nation + '\'' +
                ", duration=" + duration +
                ", score=" + score +
                '}';
    }
}

最后

完整的写完这个系统我差不多用了300行代码。顿时灵感,做个小练习,巩固java基础知识,创作不易(好一点的文章都是付费的)如果你觉得对你有一点点帮助,那就点赞,收藏,留言,有问题还可以私信我,看到了尽量回复!

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值