| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 614 人关注过本帖
标题:关于同类商品合并打印的问题
只看楼主 加入收藏
qq705570553
Rank: 1
等 级:新手上路
帖 子:9
专家分:9
注 册:2014-1-3
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
关于同类商品合并打印的问题
麻烦把合并项做一下,感激不尽
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
我的代码是这样的,但就是无法合并只能一行一行的显示,    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 编辑 ]
搜索更多相关主题的帖子: double 
2014-01-03 12:07
gmh0421
Rank: 4
等 级:业余侠客
威 望:2
帖 子:58
专家分:215
注 册:2013-10-22
收藏
得分:20 
你在打印之前把那几个清单的数组处理一下,相同名字的货品把数量和总金额相加,形成新的数组
其实推荐用集合而不是用数组更好

本人纯属菜鸟,如有不当,请各位大虾指正
希望能在不断的学习中,提高水平
2014-01-06 14:58
qq705570553
Rank: 1
等 级:新手上路
帖 子:9
专家分:9
注 册:2014-1-3
收藏
得分:0 
回复 2楼 gmh0421
谢谢,我是相同名字的货品把数量和总金额相加,还是原来的数组,同学辅助我完成的,代码如下:
System.out.println("请输入商品编号:");

                k=in.nextInt()-1;
               
               
            
            System.out.println("请输入数目:");
            shumu = in.nextDouble();
            
            if (k == 0) {
               

                SPname[k] = "addidas运动鞋";
                SPdanjia[k] = 880;
                SPshumu[k] = shumu+SPshumu[k];
               
                SPjine[k] = 880 * SPshumu[k];
               
               
               
            }
            if (k == 1) {
               

                SPname[k] = "kappa网球裙";
                SPdanjia[k] = 200;
                SPshumu[k] = shumu+SPshumu[k];
                SPjine[k] = 200 * SPshumu[k];
               

            }
不知道你用新的数组会怎么弄?

[ 本帖最后由 qq705570553 于 2014-1-6 22:39 编辑 ]
2014-01-06 22:30
gmh0421
Rank: 4
等 级:业余侠客
威 望:2
帖 子:58
专家分:215
注 册:2013-10-22
收藏
得分:0 
我也就这么一说,其实都一样,呵呵

本人纯属菜鸟,如有不当,请各位大虾指正
希望能在不断的学习中,提高水平
2014-01-07 10:22
qq705570553
Rank: 1
等 级:新手上路
帖 子:9
专家分:9
注 册:2014-1-3
收藏
得分:0 
回复 4楼 gmh0421
还有一个地方不怎么完美,它的那个只能按照顺序排列合并,但是不能跟着用户先选哪一个排列合并,麻烦解决一下
2014-02-09 18:07
qq705570553
Rank: 1
等 级:新手上路
帖 子:9
专家分:9
注 册:2014-1-3
收藏
得分:0 
回复 4楼 gmh0421
你有没有教案,就是第几节.ppt?如果没有的话我可以把我们学校的发给你
2014-02-09 18:15
快速回复:关于同类商品合并打印的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019852 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved