Java电影管理系统 (期末作业,超详细哟,拿走不谢!!!)
一、菜单展示
菜单有如下功能:
- Add a movie
- Remove a movie
- View a movie
- View all movies
- 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基础知识,创作不易(好一点的文章都是付费的)如果你觉得对你有一点点帮助,那就点赞,收藏,留言,有问题还可以私信我,看到了尽量回复!