zoukankan      html  css  js  c++  java
  • Java版本-----商店购物系统

    buy.java

    public class Buy {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Shops shops = new Shops();
    
          
        }
    
    }

    shops.java

    import java.util.Scanner;
    
    public class Shops {
        public static int m;
        public static  int numberCup = 0 , numberRubber = 0, numberPen = 0, allPrice = 0;
        /**  构 造 函 数  */
        public Shops(){
        
            showAllGoods();
        }
        
        /**    显 示 所 有 的 商 品   */
        public void showAllGoods(){
            System.out.println("欢迎来到自助超市, 我们这里有以下商品
    1.笔
    2.水杯
    3.橡皮
    4.退出
    请输入相应的编号购买:");
            Scanner scanner = new Scanner(System.in);
            int i = scanner.nextInt();
            switch (i) {
            case 1:
                System.out.println("请输入数量:");
               inputCode();
               numberPen += m;
               showAllBuyGoods();
               
                break;
            case 2:
                System.out.println("请输入数量:");
                inputCode();
                numberCup += m;
                showAllBuyGoods();
                
                break;
                
            case 3:
                System.out.println("请输入数量:");
                inputCode();
                numberRubber += m;
                showAllBuyGoods();
                break;
            case 4:
                System.exit(1);
                break;
            default:
                break;
            }
    
        }
        /**   用 户 输 入 商 品 编 码 函 数    */
        public void     inputCode(){
            Scanner scann = new Scanner(System.in);
            m = scann.nextInt();
        }
        /**    显 示 已 经 购 买 的 商 品   */
        public void     showAllBuyGoods(){
             allPrice = numberCup * 5 + numberPen * 3 + numberRubber * 2 ;
            System.out.println("你选择了"+numberPen+"只笔,"+numberCup+"个水杯,"+numberRubber+"个橡皮擦, 一共"+allPrice+"元.还需要其他的吗, 需要请输入1, 不需要请输入2.");
            isGoOn();
            
        }
        /**    看 用 户 是 否 继 续   */
        public void isGoOn(){
            Scanner scann = new Scanner(System.in);
            m = scann.nextInt();
            if (m == 1) {
                showAllGoods();
            }else if (m == 2) {
                //TODO
                allPrice = numberCup * 5 + numberPen * 3 + numberRubber * 2 ;
                buy(allPrice);
            }else{
                System.out.println("输入有误, 请重新输入.");
                isGoOn();
            }
    
        }
        /**   购 买 函  数    */
        public void buy(int a){
            if (a  > 100) {
                System.out.println("选中的物品大于100元,请删除:");
                deleteGoods();
            }else{
                System.out.println("付款成功.");
            }
    
        }
        /**  删 除 商 品    */
        public void deleteGoods(){
            System.out.println("1.笔  2.水杯  3.橡皮");
            Scanner scanner = new Scanner(System.in);
            int j = scanner.nextInt();
            switch (j) {
            case 1:
                System.out.println("请输入数量:");
               inputCode();
               numberPen -= m;
               showAllBuyGoods();
               
                break;
            case 2:
                System.out.println("请输入数量:");
                inputCode();
                numberCup -= m;
                showAllBuyGoods();
                break;
                
            case 3:
                System.out.println("请输入数量:");
                inputCode();
                numberRubber -= m;
                showAllBuyGoods();
                break;
            case 4:
                System.exit(1);
                break;
            default:
                break;
            
        }
    }
    }
  • 相关阅读:
    DevExpress 最最最基础踩坑(如何设置控件属性)
    Oracle如何创建数据库(使用图形化界面,顺便提一下UTF-8和ZB16GB字符集的问题)
    ElementUI el-dialog中嵌套子页面
    Oracle详细教程(触发器,事务,存储过程,锁,游标)
    和人事交谈下来的几点感悟
    Oracle Groupby分组缺少表达式解决方法
    leetcode973. 最接近原点的 K 个点(谈谈C#中的Icomparer,ComParer,IComparable)
    APP的闪退和无响应
    APP测试的主要内容
    python数据结构
  • 原文地址:https://www.cnblogs.com/mafeng/p/5237222.html
Copyright © 2011-2022 走看看