简易超市销售系统,参考文档:
超市销售系统.docx
输入格式:
从键盘一次性输入多行商品数据,每行包含 商品数量:正负整数,为正时不要输入“+” 商品ID:正整数,不要输入“+” (数量与ID之间用“,”隔开), exit结束"
输出格式:
Row:3 Item ID Wrong:8(若有) Row:4 Item Format Wrong(若有) 本次销售明细: Item quantiy fee xxxx nn mm
本次交易应付费用:xxxx
输入样例:
在这里给出一组输入。例如:
12,0
23,1
exit
输出样例:
在这里给出相应的输出。例如:
本次销售明细:
Item quantiy fee
Apple 12 12
Banana 23 46
本次交易应付费用:58
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Sale extends SalesLineItem {
Date date = new Date();
private int flag = 1;//完成的标志
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public int Endflag() {
return flag;
}
}
class SalesLineItem {
int everyCount;
Item everyItem;
ArrayList<SalesLineItem> salesLinesItems = new ArrayList<>();
public SalesLineItem() {
}
public SalesLineItem(int everyCount, Item item) {
this.everyCount = everyCount;
this.everyItem = item;
}
public void addSalesLineItem(SalesLineItem slt) {
boolean flag = false;
for ( SalesLineItem onsale : salesLinesItems ){
if(onsale.everyItem.getNum() == slt.everyItem.getNum()){
onsale.everyCount = onsale.everyCount + slt.everyCount;
flag = true;
if(onsale.everyCount == 0 || onsale.everyCount < 0){
salesLinesItems.remove(onsale