目录
一:案例要求:
二案例分析:
编辑三:具体代码:
四:运行结果:
一:案例要求:
二案例分析:
三:具体代码:
Ⅰ:
package three;import java.util.ArrayList;
import java.util.Collection;public class test {public static void main(String[] args) {Collection<movie> movies=new ArrayList<>();movies.add(new movie("《肖生克的救赎》" , 9.7 , "罗宾斯"));movies.add(new movie("《霸王别姬》" , 9.7 , "张国荣"));movies.add(new movie("《狗的七世》" , 9.7 , "金毛"));movies.add(new movie("《僵尸世界大战》" , 9.7 , "毛国人"));for (movie movie : movies) {System.out.println("电影名"+movie.getName()+" 评分"+movie.getScore()+" 演员"+movie.getActor());}}}
Ⅱ:实体类:
package three;public class movie {private String name;private double score;private String actor;public movie() {}public movie(String name, double score, String actor) {this.name = name;this.score = score;this.actor = actor;}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;}
}