问题:下面是前4问的代码,第5问不会写【 创建一个方法:查询最终购买价,大于指定数字的所有商品。】
老师具体代码应该怎么写?
/**
* 遍历(ToString)
*/
public class Test91 {
public static void main(String[] args) {
Product m0 = new Product(1, "百战鼠标", "BZ_001", 99.21, 0.9);
Product m1 = new Product(2, "键盘侠玩偶", "WO_102", 403.0, 0.7);
Product m2 = new Product(3, "实战java程序设计", "BK_001", 89.0, 0.8);
Product m3 = new Product(4, "高淇牌西装", "GQ_XF_12", 700.0, 0.5);
Product m4 = new Product(5, "大米牌手机", "DM_PH_13", 900.0, 0.3);
//Product[] p =new Product[]{m0,m1,m2,m3,m4};
//Product[] p ={m0,m1,m2,m3,m4};
Product[] p = new Product[5];
p[0] = m0;
p[1] = m1;
p[2] = m2;
p[3] = m3;
p[4] = m4;
for (int i=0;i<p.length;i++) {
System.out.println(p[i]);
}
}
}
class Product {
private int id;
private String name;
private String model;
private double price;
private double discount;
Product() {
}
@Override
public String toString() {
return getId()+"\t"+getName()+"\t"+getModel()+"\t"+getPrice()+"\t"+getDiscount();
}
public Product(int id, String name, String model, double price, double discount) {
this.id = id;
this.name = name;
this.model = model;
this.price = price;
this.discount = discount;
}
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 String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getDiscount() {
return discount;
}
public void setDiscount(double discount) {
this.discount = discount;
}
}