62,614
社区成员
发帖
与我相关
我的任务
分享
public class Commodity {
private int commCount;
private String commName;
private double commPrice;
private double commTax;
/**
* @return the commCount
*/
public int getCommCount() {
return commCount;
}
/**
* @return the commName
*/
public String getCommName() {
return commName;
}
/**
* @return the commPrice
*/
public double getCommPrice() {
return commPrice;
}
/**
* @return the commTax
*/
public double getCommTax() {
return commTax;
}
/**
* @param commCount the commCount to set
*/
public void setCommCount(int commCount) {
this.commCount = commCount;
}
/**
* @param commName the commName to set
*/
public void setCommName(String commName) {
this.commName = commName;
}
/**
* @param commPrice the commPrice to set
*/
public void setCommPrice(double commPrice) {
this.commPrice = commPrice;
}
/**
* @param commTax the commTax to set
*/
public void setCommTax(double commTax) {
this.commTax = commTax;
}
}
public class TestDemo {
public static void main(String[] agrs)
{
List<Commodity> list=new ArrayList<Commodity>();
Commodity comm=null;
Scanner scanner=new Scanner(System.in);
boolean isBuying=true;
boolean showResult=false;
String commName="";
int commCount=0;
double commPrice=0.0;
System.out.println("**********开始购买或者继续购买请输入ON,如果购买结束,请输入Exit********");
while(isBuying)
{
String isBegining=scanner.nextLine();
if(isBegining.toLowerCase().equals("on"))
{
showResult=true;
System.out.println("please input commodity name:");
commName=scanner.nextLine();
System.out.println("please input commodity count:");
commCount=scanner.nextInt();
System.out.println("please input commodity price:");
commPrice=scanner.nextDouble();
comm=new Commodity();
comm.setCommName(commName);
comm.setCommCount(commCount);
comm.setCommPrice(commPrice);
comm.setCommTax(commPrice*0.05);
list.add(comm);
}
if(isBegining.toLowerCase().equals("exit"))
{
scanner.close();
isBuying=false;
}
}
double sumPrice=0.0;
if(showResult){
for(int i=0;i<list.size();i++)
{
Commodity commEnd=(Commodity)list.get(i);
System.out.println("你购买的商品有:");
System.out.println("名称:"+commEnd.getCommName()+" "+"数量:"+commEnd.getCommCount()+"件"
+" "+"单价:"+commEnd.getCommPrice()+"元"+" "+"税:"+commEnd.getCommTax()+"元");
sumPrice=+commEnd.getCommPrice();
}
System.out.println("您本次消费:"+(sumPrice+sumPrice*0.05)+"元");
System.out.println("商品消费总计:"+sumPrice+"元"+"商品税总计:"+sumPrice*0.05+"元");
}
else
{
System.out.println("您没有购买商品");
}
}
}