一案例要求:
二具体代码(需要在同一个包下创建三个类)
Ⅰ:实现类
package 重修;import java.util.Random;
import java.util.Scanner;public class first {public static void main(String[] args) {javabean[]movies=new javabean[4];movies[0]= new javabean("水门桥", 23.5,123,1);movies[1]= new javabean("西游记", 23.5,123,2);movies[2]= new javabean("星游记", 23.5,123,3);movies[3]= new javabean("活着", 23.5,123,4);javabeanoperate s=new javabeanoperate(movies);s.show();Scanner sc=new Scanner(System.in);int x;System.out.print("请输入要查询的编号:");x= sc.nextInt();System.out.println();s.search(x);}
}
Ⅱ实体类:
package 重修;public class javabean {private String name;private double price;private double score;private int id;public javabean() {}public javabean(String name, double price, double score, int id) {this.name = name;this.price = price;this.score = score;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 int getId() {return id;}public void setId(int id) {this.id = id;}
}
Ⅲ操作类:
package 重修;public class javabeanoperate {private javabean[] javabeans;public javabeanoperate(javabean[] movies) {this.javabeans = movies;}public void show(){System.out.println("-------全部电影信息如下-------");for (int i = 0; i < javabeans.length; i++) {javabean m = javabeans[i];System.out.println("姓名" + m.getName() + " 价格 " + m.getPrice() + " 评分 " + m.getScore() + "编号 " + m.getId());System.out.println("-----------------------");}}public void search(int id){for (int i = 0; i < javabeans.length; i++) {javabean m = javabeans[i];if(m.getId()==id){System.out.println("找到了");System.out.println("姓名" + m.getName() + " 价格 " + m.getPrice() + " 评分 " + m.getScore() + "编号 " + m.getId());return ;}}System.out.println("未查到该编号相关信息");}
}