你好老师,关于折后价格,我想新建一个类,用组合的方法计算出折后价格再进行比较,写不下去了,蒙了,麻烦你用组合的方法补齐一下我的代码,谢谢
package com.luzhongxu.arrary;
public class Test08 {
public static void main(String[] args) {
shangpings x0 = new shangpings(1,"鼠标","BZ",99.21,0.9);
shangpings x1 = new shangpings(2,"键盘","WO",403.00,0.7);
shangpings x2 = new shangpings(3,"程序设计","BK",89.00,0.8);
shangpings x3 = new shangpings(4,"西装","GQ",700.00,0.5);
shangpings x4 = new shangpings(5,"手机","DM",900.00,0.3);
shangpings[] x = new shangpings[5];
x[0] = x0;
x[1] = x1;
x[2] = x2;
x[3] = x3;
x[4] = x4;
for(int i = 0;i<x.length;i++){
System.out.println(x[i]);
}
}
}
class shangpings{
int id;
String mingcheng;
String xinghao;
double price;
double discount;
shangpings(){}
public shangpings(int id, String mingcheng, String xinghao, double price, double discount) {
this.id = id;
this.mingcheng = mingcheng;
this.xinghao = xinghao;
this.price = price;
this.discount = discount;
}
@Override
public String toString() {
return "序号:"+getId()+"\t"+"名称:"+getMingcheng()+"\t"+"型号:"+getXinghao()+"\t"+"价格:"+getPrice()+"\t"+"折扣:"+getDiscount();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getMingcheng() {
return mingcheng;
}
public void setMingcheng(String mingcheng) {
this.mingcheng = mingcheng;
}
public String getXinghao() {
return xinghao;
}
public void setXinghao(String xinghao) {
this.xinghao = xinghao;
}
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;
}
}
class zhehou { //zhehou= 折后价格
shangpings sp = new shangpings();
double zhehou;
public void zhehou(double price,double discount,double zhehou){
this.sp.price = price;
this.sp.discount = discount;
this.zhehou = zhehou;
zhehou = price*discount;
System.out.println(zhehou);
}
}