拼单点外卖,AA付款

中午点外卖,发现有的同事点的多,有的同事点的少,大家合在一起点不仅能减少配送费,达到一定价格还有满减活动,很不错。介于大伙都不是土豪,采用AA点餐,按比例付款的方式。
每个人最后应付费用 = 每个人总费用/折扣前拼单总费用*折扣后拼单的总费用。

下面是我用elipse工具写的简单java代码,解决点外卖AA付款的问题:

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        List<BillBean> list=new ArrayList<>();
        float endPrice=0;
        float totalPrice=0;
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while(true){
                System.out.println("Enter name(Over input 'N'):"); 
                String name=br.readLine();
                if(name.isEmpty()){
                    System.out.println("Enter name(Over input 'N'):"); 
                }
                if(name.equals("N")){
                    break;
                }
                BillBean billBean1=new BillBean();
                billBean1.name=name;

                while(true){    
                    System.out.println("Enter price(Over input 'N', Clean input C):"); 
                    String price=br.readLine();
                    if(price.isEmpty()){
                        System.out.println("Enter price(Over input 'N', Clean input C):"); 
                    }
                    if(price.equals("N")){
                        break;
                    }
                    if(price.equals("")){
                        break;
                    }
                    if(price.equals("C")){
                        billBean1.total -= billBean1.costList.get(billBean1.costList.size()-1);
                        System.out.println("Clean the last price success"); 
                        continue;
                    }
                    billBean1.costList.add(Float.parseFloat(price));
                    billBean1.total += Float.parseFloat(price);
                }
                list.add(billBean1);
                totalPrice+=billBean1.total;
                System.out.println("Name:"+name+" Total price:"+billBean1.total); 
            }

            System.out.println("Enter discount total price:"); 
            String endTotal=br.readLine();
            if(endTotal.isEmpty()){
                System.out.println("Enter name(Over input 'N'):"); 
            }
            if(!endTotal.equals("N")){
                endPrice=Float.parseFloat(endTotal);
            }
            System.out.println("------------------start------------------"); 
            for(BillBean b: list){
                System.out.println("Name:"+b.name+" Total price:"+b.total+" End total price:"+b.total/totalPrice*endPrice+"\n"); 
            }
            System.out.println("------------------end------------------"); 



        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

    }

}
public class BillBean {

    public String name;
    public List<Float> costList=new ArrayList<>();
    public float total=0;

}

使用步骤按照提示即可,在数字的判别上没做处理,比较脆弱。小心一点还是能用的,放张演示图片。有需要的朋友可以试试看。
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值