Java实现简单的售货机程序2

             **今天给大家带来一个简单的售货机程序。**

主要流程:
1.利用数组实现相关商品的存储和价格。
2.利用三个函数:
(1)menu():主菜单,用于实现商品的展示和基本选择。
(2)getnumber():获得商品的数量,并且计算价格。
(3)huode():输入你个人的金额,并且判断是否满足商品的总价 格,若满足,则计算找零价格。并且选择返回主界面或者是退出,若不满足,根据用户选择是否决定重新输入产品质量或者是返回主界面或者是退出界面。

 public void huode(int choice)//计算找零
    {
     float thingprice;//商品总价格
     int nideshuru;//你输入钱数
        float jieguo;//找零数目
        int choice1;//返回主界面或者退出的选择
        thingprice=getnumber(choice);
        System.out.println("请输入你的金额:");
        Scanner s=new Scanner(System.in);
        nideshuru=s.nextInt();
        while(nideshuru<0||nideshuru>100)
       {
        System.out.println("你的输入格式错误");
        System.out.println("请重新输入:");
        nideshuru=s.nextInt();
       }//判断顾客输入价格是否满足条件
        if(nideshuru>thingprice)
        {
         jieguo=nideshuru-thingprice;
         System.out.printf("找零金额:%.2f",jieguo);
         System.out.println("是否返回页面?1.是/n2.不是(任意键)");
           choice1=s.nextInt();
           if(choice1==1)
          {charrr.menu();
           }
          else
           System.exit(0);
        }
        else
         {System.out.println("你的钱不够!");//设置重新选择商品数量,返回界面,退出。
            System.out.println("是否重新选择?1.改变购买数量。/n2.返回主界面。/n3.按任意键退出。");
            choice1=s.nextInt();
            if(choice1==1)
              {charrr.getnumber(choice1);
              this.huode(choice);}
            if(choice1==2)
              charrr.menu();
            else
             System.exit(0);}}
             public static void main(String[] args) {//调用主菜单函数
              charrr.menu();}}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值