完成电影信息展示功能;根据电影id查询该电影的详细
主方法:
package Y;
import java.util.Scanner;
public class 模仿电影系统main {
//目标:完成电影信息展示功能;根据电影id查询该电影的详细
//电影数据
// 1,"水门桥",38.9,9.8,"徐克","吴京","12万人想看"
// 2,"出学吧",39,7.8,"唐晓白","田雨","3.5万人想看"
// 3,"月球陨落",42,7.9,"罗兰","贝瑞","17.9万人想看"
// 4,"一点到家",35,8.7,"许宏宇","刘昊然","10.8万人想看"
public static void main(String[] args) {
//1、设计一个电影类
//2、设计一个电影的操作类
//3、定义一个movie01类型的数组接受电影信息;定义电影类型的数组
movie01 moove[] = new movie01[4];//此时是设置了四个电影
movie01 m1 = new movie01( 1,"水门桥",38.9,9.8,"徐克","吴京","12万人想看");
movie01 m2 = new movie01( 2,"出学吧",39,7.8,"唐晓白","田雨","3.5万人想看");
movie01 m3 = new movie01( 3,"月球陨落",42,7.9,"罗兰","贝瑞","17.9万人想看");
movie01 m4= new movie01( 4,"一点到家",35,8.7,"许宏宇","刘昊然","10.8万人想看");
//4、把对象存入到数组moove当中
moove[0]=m1;
moove[1]=m2;
moove[2]=m3;
moove[3]=m4;
/* 相当于上述创建的对象,也是把对象同时存入到数组中
moove[0]=new 模仿电影系统方法01( 1,"水门桥",38.9,9.8,"徐克","吴京","12万人想看");
moove[1]=new 模仿电影系统方法01( 2,"出学吧",39,7.8,"唐晓白","田雨","3.5万人想看");
moove[2]=new 模仿电影系统方法01( 3,"月球陨落",42,7.9,"罗兰","贝瑞","17.9万人想看");
moove[3]=new 模仿电影系统方法01( 4,"一点到家",35,8.7,"许宏宇","刘昊然","10.8万人想看");
*/
movie02 y = new movie02(moove);
tuichu: while (true){//设置一个死循环,持续打印如下代码
System.out.println("=====电影信息系统=====");
System.out.println("1.展示系统中的全部电影信息");
System.out.println("2.展示对应编号的电影详细");
System.out.println("3.退出");
System.out.println("请输入您的操作指令");
Scanner Y = new Scanner(System.in);
int select = Y.nextInt();
if (select == 1) {//若输入的是1的话进入(模拟电影系统方法02)
y.printAll();
// break;
}else if (select == 2) {
System.out.println("请输入要查询电影的编号");
int id = Y.nextInt();
y.printChoose(id);
// break;
}else if (select == 3){
break ;
}
else {
System.out.println("您输入的指令有问题!请重新输入");
}
}
}
}
存数据类:
package Y;
//此处是设置了一个电影类
public class movie01 {
private int id;//定义电影的编号
private String name;//定义电影的名字
private double price;//定义电影的价格
private double score;//定义电影的评分
private String daoyan;//定义导演信息
private String actor;//定义演员信息
private String info;//定义其他信息
//定义一个有参构造器接受数据
public movie01(int id, String name, double price, double score, String daoyan, String actor, String info) {
this.id = id;
this.name = name;
this.price = price;
this.score = score;
this.daoyan = daoyan;
this.actor = actor;
this.info = info;
}
//无参构造器
public movie01(){}
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 getDaoyan() {
return daoyan;
}
public void setDaoyan(String daoyan) {
this.daoyan = daoyan;
}
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;
}
}
进行数据操作的类:
package Y;
//此处是设计了一个电影的操作类
public class movie02 {
//1、定义电影数组接受多部电影
private movie01 movies[];//moives其实就相当于一个一个的电影对象
//2、定义一个有参构造器接受这个多部电影
public movie02(movie01 movies[]){
this.movies = movies;
}
//3、展示所有电影
public void printAll(){
for(int i=0;i<movies.length;i++){
System.out.println("-----系统全部电影信息如下-----");
System.out.println("编号:"+movies[i].getId());
System.out.println("名称:"+movies[i].getName());
System.out.println("价格:"+movies[i].getPrice());
System.out.println("--------------------");
}
}
public void printChoose(int id) {
for(int i=0;i<movies.length;i++){
if(movies[i].getId() == id){
System.out.println("-----编号为"+(i+1)+"的电影具体信息如下-----");
System.out.println("编号:"+movies[i].getPrice());
System.out.println("名称:"+movies[i].getName());
System.out.println("价格:"+movies[i].getPrice());
System.out.println("评分:"+movies[i].getScore());
System.out.println("导演信息:"+movies[i].getDaoyan());
System.out.println("演员信息:"+movies[i].getActor());
System.out.println("其他信息:"+movies[i].getInfo());
System.out.println("--------------------");
return;//表示已经找到了,结束了
}
}
System.out.println("没有该电影信息~~");//因为上面return跳出了方法,这条输出则不执行
}
}