1.设计电影对象
2创建三个电影对象,封装电影信息
Movie m1=new Movie("长津湖",9.4,"吴京");
Movie m2=new Movie("我和我的父辈",8.7,"吴京");
Movie m3=new Movie("扑水少年",9.5,"王川");
3.定义一个电影类型数组,存储三部电影对象
package com.yuyang.javabean;
public class Movie {
private String name;
private double score;
private String actor;
public Movie(String name, double score, String actor) {
this.name = name;
this.score = score;
this.actor = actor;
}
public Movie() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public String getActor() {
return actor;
}
public void setActor(String actor) {
this.actor = actor;
}
}
package com.yuyang.javabean;
public class Test2 {
public static void main(String[] args) {
//1.设计电影对象
//2创建三个电影对象,封装电影信息
// Movie m1=new Movie("长津湖",9.4,"吴京");
// Movie m2=new Movie("我和我的父辈",8.7,"吴京");
// Movie m3=new Movie("扑水少年",9.5,"王川");
//3.定义一个电影类型数组,存储三部电影对象
Movie[] movies=new Movie[3];
movies[0]=new Movie("长津湖",9.4,"吴京");
movies[1]=new Movie("我和我的父辈",8.7,"吴京");
movies[2]=new Movie("扑水少年",9.5,"王川");
//4.遍历数组中的每个对象获取它的信息,展示出来
for (int i = 0; i < movies.length; i++) {
Movie m=movies[i];
System.out.println("电影名称:"+m.getName());
System.out.println("评分:"+m.getScore());
System.out.println("主演:"+m.getActor());
System.out.println("=====================");
}
}
}
电影名称:长津湖
评分:9.4
主演:吴京
=====================
电影名称:我和我的父辈
评分:8.7
主演:吴京
=====================
电影名称:扑水少年
评分:9.5
主演:王川
=====================