movie
public class movie {
private int id;
private String title;
private String time;
private double score;
private String area;
private String type;
private String director;
private String starring;
public movie() {
}
public movie(int id, String title, String time, double score, String area, String type, String director, String starring) {
this.id = id;
this.title = title;
this.time = time;
this.score = score;
this.area = area;
this.type = type;
this.director = director;
this.starring = starring;
}
/**
* 获取
* @return id
*/
public int getId() {
return id;
}
/**
* 设置
* @param id
*/
public void setId(int id) {
this.id = id;
}
/**
* 获取
* @return title
*/
public String getTitle() {
return title;
}
/**
* 设置
* @param title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* 获取
* @return time
*/
public String getTime() {
return time;
}
/**
* 设置
* @param time
*/
public void setTime(String time) {
this.time = time;
}
/**
* 获取
* @return score
*/
public double getScore() {
return score;
}
/**
* 设置
* @param score
*/
public void setScore(double score) {
this.score = score;
}
/**
* 获取
* @return area
*/
public String getArea() {
return area;
}
/**
* 设置
* @param area
*/
public void setArea(String area) {
this.area = area;
}
/**
* 获取
* @return type
*/
public String getType() {
return type;
}
/**
* 设置
* @param type
*/
public void setType(String type) {
this.type = type;
}
/**
* 获取
* @return director
*/
public String getDirector() {
return director;
}
/**
* 设置
* @param director
*/
public void setDirector(String director) {
this.director = director;
}
/**
* 获取
* @return starring
*/
public String getStarring() {
return starring;
}
/**
* 设置
* @param starring
*/
public void setStarring(String starring) {
this.starring = starring;
}
}
movieService
import java.util.Scanner;
public class MovieService {
private movie[] movies;
Scanner sc = new Scanner(System.in);
public MovieService(movie[] movies){
this.movies=movies;
}
/*
启动电影信息管理系统
*/
public void start() {
lo:
while (true) {
System.out.println("------------电影信息管理系统----------");
System.out.println("请输入你的选择:");
System.out.println("1.查询全部电影信息");
System.out.println("2.根据id查询电影信息");
System.out.println("3.退出");
int choice = sc.nextInt();
switch (choice){
case 1:
queryMovieInfos();
break;
case 2:
queryMovieInfoByID();
break;
case 3:
System.out.println("感谢使用,拜拜");
break lo;
default:
System.out.println("输入有误");
break;
}
}
}
/*根据电影编号,查询电影的详细信息*/
private void queryMovieInfoByID() {
//1.键盘录入用户输入的编号
System.out.println("请输入要查询的电影编号");
int id=sc.nextInt();
//2.遍历数组,从数组中查询电影信息
for (int i = 0; i < movies.length; i++) {
movie movie = movies[i];//快捷键 movies[i].var
movie.getId();
if(movie.getId()==id){
//3.将找到的电影信息,打印在控制台=
System.out.println(movie.getId()+"---"+movie.getTitle()+"---");
return;
}
//走到这里,说明没找到
System.out.println("输入变化不存在,重新输入");
}
}
/*展示系统中全部的电影(名称、评分)*/
private void queryMovieInfos() {
//1.遍历数组,取出每一个电影对象
for (int i = 0; i < movies.length; i++) {
movie movie = movies[i];
//System.out.println(movies); 打印对象名,会看到内存地址
//2.通过电影对象,调用内部getXX方法,获取信息并打印
System.out.println(movie.getTitle()+"---"+movie.getScore());
}
}
}
test
public class Test {
public static void main(String[] args) {
movie movie1 = new movie(1,"东八区的先生们","2022",2.1,"中国大陆","剧情:喜剧","夏睿","王晓晨");
movie movie2 = new movie(2,"东八区的先生","2022",2.1,"中国大陆","剧情:喜剧","夏睿","王晓晨");
movie movie3 = new movie(3,"东八区的先","2022",2.1,"中国大陆","剧情:喜剧","夏睿","王晓晨");
movie[] movies = {movie1,movie2,movie3};//将对象封装在数组中
//数组存储对象的时候,存储的是对象的地址值
//如何将一个类 中的 数据传递给另外一个类
//可以在创建对象的时候,利用传参传过去
MovieService movieService =new MovieService(movies);
movieService.start();
}
}