package com.Demo;
import java.util.Scanner;
public class DYtest {
public static void main(String[] args) {
//1.设计一个电影类
//2.设置一个电影操作类
//3.准备 全部电影信息
DY1[] movie=new DY1[4];
DY1 m1=new DY1(1,"水门桥",38.9,9.8,"徐克","吴京","12万人想要观看");
DY1 m2=new DY1(2,"水门桥",38.9,9.8,"徐克","吴京","12万人想要观看");
DY1 m3=new DY1(3,"水门桥",38.9,9.8,"徐克","吴京","12万人想要观看");
DY1 m4=new DY1(4,"水门桥",38.9,9.8,"徐克","吴京","12万人想要观看");
//存储
movie[0]=m1;
movie[1]=m2;
movie[2]=m3;
movie[3]=m4;
//4.创建一个电影创作类的对象,接受电影数据,并对其业务处理
DYoperator dYoperator=new DYoperator(movie);
dYoperator.searMovieById(3);
Scanner sc=new Scanner(System.in);
while (true) {
System.out.println("电影信息系统");
System.out.println("1.查询全部电影信息");
System.out.println("2.根据ID查询某个电影的详细信息展示");
System.out.println("请您输入操作命令:");
int commd=sc.nextInt();
switch (commd){
case 1:
dYoperator.printALL();
break;
case 2:
System.out.println("亲您输入查询id:");
int id= sc.nextInt();
dYoperator.searMovieById(id);
break;
default:
System.out.println("您输入的命令有问题");
}
}
}
}
package com.Demo;
public class DYoperator {
private DY1[] movies;
public DYoperator(DY1[] movies){
this.movies=movies;
}
//1.展示系统全部电影信息
public void printALL(){
System.out.println("系统全部电影信息如下:");
for (int i = 0; i < movies.length; i++) {
DY1 m=movies[i];
System.out.println("编号"+m.getId());
System.out.println("名称"+m.getName());
System.out.println("价格"+m.getPrice());
System.out.println("-------------------------");
}
}
//2.根据电影的编号查询出该电影的详细信息展示
public void searMovieById(int id){
System.out.println("系统全部电影信息如下:");
for (int i = 0; i < movies.length; i++) {
DY1 m = movies[i];
if (m.getId()==id){
System.out.println("该电影详情如下:");
System.out.println("编号"+m.getId());
System.out.println("名称"+m.getName());
System.out.println("价格"+m.getPrice());
System.out.println("得分"+m.getScore());
System.out.println("导演"+m.getDirector());
System.out.println("主演"+m.getActor());
System.out.println("其他信息"+m.getInfo());
System.out.println("-------------------------");
return;//找到电影信息跳出循环
}
}
System.out.println("没有电影信息");
}
}
package com.Demo;
public class DY1 {
private int id;
private String name;
private double price;
private double score;
private String director;
private String actor;
private String info;
public DY1() {
}
public DY1(int id, String name, double price, double score, String director, String actor, String info) {
this.id = id;
this.name = name;
this.price = price;
this.score = score;
this.director = director;
this.actor = actor;
this.info = info;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getActor() {
return actor;
}
public void setActor(String actor) {
this.actor = actor;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
}