一、问题
这一集课后作业做完了,想让老师给检查一下,看看有没有问题,是不是达到了这次课后作业的要求
作业要求如图:

二、作业源码
package com.bjsxt.array;
/**
* 完成功能:
* 1. 定义一个类表示上表中的商品。
* 2. 创建 5 个对象存储上面表的信息。
* 3. 创建一个数组,存储这 5 个对象。
* 4. 再创建一个方法,遍历(toString())这个数组,打印表的信息。
* 5. 创建一个方法:查询最终购买价,大于指定数字的所有商品。
*
*/
public class Test05zuoye {
public void print(double m){
Info info0 = new Info(1,"百战牌鼠标", "BZ_001", 99.21 ,0.9);
Info info1 = new Info(2,"键盘侠玩偶", "WO_102", 403.00 ,0.7);
Info info2 = new Info(3,"实战尚学堂", "java", 89.00 ,0.8);
Info info3 = new Info(4,"高淇牌西装", "GQ_XF_12", 700.00 ,0.5);
Info info4 = new Info(5,"大米牌手机", "DM_PH_13", 900.00 ,0.3);
Info[] infos = new Info[5];
infos[0] = info0;
infos[1] = info1;
infos[2] = info2;
infos[3] = info3;
infos[4] = info4;
for (int i = 0;i<infos.length;i++){
System.out.println(infos[i]);
for (int j = 0 ;j<infos.length;j++){
System.out.println("遍历所有:"+infos[j].getName()+" "+infos[j].getPrice()+" "+infos[j].getCheap());
if((infos[j].getPrice())*(infos[j].getCheap())>m){
System.out.println("打折后的价格:"+(infos[j].getPrice())*(infos[j].getCheap()));
System.out.println("输出结果:"+infos[j].getName());
System.out.println("===================================");
}else{
System.out.println("最终购买价小于指定数字,抱歉!");
}
}
}
}
public static void main(String[] args) {
Test05zuoye test05zuoye = new Test05zuoye();
test05zuoye.print(100);
}
}
class Info{
private int id;
private String name;
private String type;
private double price;
private double cheap;
@Override
public String toString() {
return
"id=" + id +'\t'+
"name='" + name + '\t' +
"type='" + type + '\t' +
"price=" + price +'\t'+
"cheap=" + cheap +'\t'
;
}
public Info(){
}
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 getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getCheap() {
return cheap;
}
public void setCheap(double cheap) {
this.cheap = cheap;
}
public Info(int id, String name, String type, double price, double cheap) {
this.id = id;
this.name = name;
this.type = type;
this.price = price;
this.cheap = cheap;
}
}
三、运行结果
