关于同类商品合并打印的问题
麻烦把合并项做一下,感激不尽
我的代码是这样的,但就是无法合并只能一行一行的显示, public void jiesuan(double[] KHname, String[] KHshengri, double[] KHjifen,String[] SPname, double[] SPdanjia, double[] SPshumu,
double[] SPjine, double[] jiancei) {
double sum = 0;
double sumjifen = 0;
double bianhao = 0;
double shumu = 0;
System.out.println("*************************************************");
System.out.println("请选择购买的商品编号:");
System.out.println("1.addidas运动鞋");
System.out.println("2.Kappa网球裙");
System.out.println("3.网球拍");
System.out.println("4.addidasT恤");
System.out.println("5.Nike运动鞋");
System.out.println("6.kappa网球");
System.out.println("7.kappaT恤");
System.out.println("*************************************************");
System.out.println("请输入会员号:");
double name = in.nextDouble();
String jixu = "(n)";
for (int i = 0; i < KHname.length; i++) {
if (KHname[i] == name) {
jixu = "y";
}
SPname[i] = null;
SPdanjia[i] = 0;
SPshumu[i] = 0;
SPjine[i] = 0;
}
int k = 0;
int spshu = 0;
double shumuhe1 = 0;
double shumu1 = 0;
while (jixu.equals("y")) {
System.out.println("请输入商品编号:");
bianhao = in.nextDouble();
System.out.println("请输入数目:");
shumu = in.nextDouble();
if (bianhao == 1) {
SPname[k] = "addidas运动鞋";
SPdanjia[k] = 880;
SPjine[k] = 880 * shumu;
double d = 880;
SPshumu[k] = shumu;
sum = sum + d * shumu;
k++;
}
if (bianhao == 2) {
SPshumu[k] = shumu;
SPname[k] = "kappa网球裙";
SPdanjia[k] = 200;
SPjine[k] = 200 * shumu;
double d = 200;
sum = sum + d * shumu;
k++;
}
spshu++;
System.out.println("商品数为" + spshu);
System.out.println("是否继续(y/n)");
jixu = in.next();
}
/*if (jixu.equals("n")) {
for (int i = 0; i < spshu; i++) {
if (SPname[i].equals("addidas运动鞋")) {
SPname[i] = "addidas运动鞋";
SPdanjia[i] = 880;
double d = 880;
shumu1 = shumu1 + shumu;
SPshumu[i] = shumu1;
sum = sum + d * shumu;
SPjine[i] = 880 * SPshumu[k];
}
continue;
}*/
System.out.println("*****************消费清单*************");
System.out.println("**");
System.out.println("物品\t\t\t单价\t\t\t个数\t\t\t金额\t");
for (int i = 0; i < KHname.length; i++) {
/*
* if (SPname[i] == null) { continue; }
*/
System.out.println(SPname[i] + "\t\t\t" + SPdanjia[i]
+ "\t\t\t" + SPshumu[i] + "\t\t\t¥" + SPjine[i]);
}
System.out.println("金额总计:¥" + sum);
System.out.print("实际交费:¥");
double shijiao = in.nextDouble();
System.out.println("找钱:¥" + (shijiao - sum));
for (int i = 0; i < KHname.length; i++) {
if (KHname[i] == name && sum > 10000) {
sumjifen = sum * 0.1;
KHjifen[i] = KHjifen[i] + sumjifen;
System.out.println("本次所获得的积分是:" + sumjifen);
break;
}
if (KHname[i] == name && sum > 5000) {
sumjifen = sum * 0.07;
KHjifen[i] = KHjifen[i] + sumjifen;
System.out.println("本次所获得的积分是:" + sum * 0.07);
break;
}
if (KHname[i] == name && sum > 3000) {
sumjifen = sum * 0.05;
KHjifen[i] = KHjifen[i] + sumjifen;
System.out.println("本次所获得的积分是:" + sum * 0.05);
break;
}
if (KHname[i] == name && sum >= 0) {
sumjifen = sum * 0.03;
KHjifen[i] = KHjifen[i] + sumjifen;
System.out.println("本次所获得的积分是:" + sum * 0.03);
break;
}
}
System.out.print("按n返回上一级菜单");
String xuanze201 = in.next();
if (xuanze201.equals("n")) {
zhu2(KHname, KHshengri, KHjifen, SPname, SPdanjia, SPshumu, SPjine,
jiancei);
}
}
[ 本帖最后由 qq705570553 于 2014-1-3 12:11 编辑 ]