一道Java编程题 求源代码

2024-12-16 00:30:07
推荐回答(1个)
回答1:

public class Invoice {

String bianhao = null;

String shuoming = null;

int count = 0;

double price = 0.0;

public Invoice(String bianhao, String shuoming, int count, double price) {
this.bianhao = bianhao;
this.shuoming = shuoming;

if (count < 0) {
this.count = 0;
} else {
this.count = count;
}

if (price < 0.0) {
this.price = 0.0;
} else {
this.price = price;
}

}

public double getInvoiceAmount() {
return count * price;
}

public String getBianhao() {
return bianhao;
}

public void setBianhao(String bianhao) {
this.bianhao = bianhao;
}

public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

public String getShuoming() {
return shuoming;
}

public void setShuoming(String shuoming) {
this.shuoming = shuoming;
}

}

public class InvoiceTest {

/**
* @param args
*/
public static void main(String[] args) {
Invoice invoice = new Invoice("010220", "Desk", 50, 53.9);

System.out.println(invoice.getInvoiceAmount());
}

}