当我购买商品的时候,我会收到一个收据,上面有我所
购买的所有商品的名称和价格(价格中包括了税款)。
收据上还有所有商品的价格总和已经税款总和。商品的
零售价格包括基本价格和税。税的计算约进到最近的
0.05。
请设计一款打印收据的程序。
输入:
输入 1:
1本12.49的书
1张14.99的CD
1块0.85的巧克力
输入2:
1盒10.00的进口巧克力
1瓶47.50的进口香水
输入 3:
1瓶27.99的进口香水
1瓶18.99的香水
1瓶9.75的感冒药
1盒11.25的进口巧克力
输出:
输出 1:
1 书 : 12.49
1 CD: 16.49
1 巧克力: 0.85
税款: 1.50
总计: 29.83
输出 2:
1 进口巧克力: 10.50
1 进口香水: 54.65
税款: 7.65
总计: 65.15
输出 3:
1 进口香水: 32.19
1 香水: 20.89
1 感冒药: 9.75
1 进口巧克力: 11.85
税款: 6.70
总计: 74.68
购买的所有商品的名称和价格(价格中包括了税款)。
收据上还有所有商品的价格总和已经税款总和。商品的
零售价格包括基本价格和税。税的计算约进到最近的
0.05。
请设计一款打印收据的程序。
输入:
输入 1:
1本12.49的书
1张14.99的CD
1块0.85的巧克力
输入2:
1盒10.00的进口巧克力
1瓶47.50的进口香水
输入 3:
1瓶27.99的进口香水
1瓶18.99的香水
1瓶9.75的感冒药
1盒11.25的进口巧克力
输出:
输出 1:
1 书 : 12.49
1 CD: 16.49
1 巧克力: 0.85
税款: 1.50
总计: 29.83
输出 2:
1 进口巧克力: 10.50
1 进口香水: 54.65
税款: 7.65
总计: 65.15
输出 3:
1 进口香水: 32.19
1 香水: 20.89
1 感冒药: 9.75
1 进口巧克力: 11.85
税款: 6.70
总计: 74.68
你自己先做,遇到什么问题,再来问。
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("您没有购买商品");
}
}}