超市收银系统Java

复制代码
package SCaa;

import java.util.Scanner;

public class yin {
//    b储存商品名字
    String[] b;
//    bb商品价格
    double[] bb;
//    商品的总额
    double c = 0;

    public void yin() {
        System.out.println("---------------录入商品----------------");
        System.out.println("请输入商品数量");
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
//        a 数组长度
        bb = new double[a];
        b = new String[a];
        for (int i = 1; i <= a; i++) {
            System.out.println("请输入第" + i + "件商品名称");
            b[i - 1] = sc.next();
            System.out.println("请输入第" + i + "件商品价格");
            bb[i - 1] = sc.nextDouble();
            c += bb[i - 1];
        }
    }

    public void yinr() {
        System.out.println("------------------我的购物车---------------");
        for (int i = 0; i < bb.length; i++) {
            System.out.println("名称" + b[i]);
            System.out.println("价格" + bb[i]);
        }
        System.out.println(c);
    }

    public void jie() {
        System.out.println("你要支付" + c);
        double cc;
        Scanner sc = new Scanner(System.in);

        cc = sc.nextDouble();
        while (cc <= c) {

            System.out.println("你钱不够请重新输入");
            cc = sc.nextDouble();

        }
        System.out.println("给你找钱" + (cc - c));
    }

    public static void main(String[] args) {
        int a;
        yin ss = new yin();
        do {
            System.out.println("欢迎使用超市结算系统");
            System.out.println("***********************************");
            System.out.println("1;商品录入");
            System.out.println("2;我的购物车");
            System.out.println("3;结算");
            System.out.println("4;退出");
            System.out.println("***********************************");
            System.out.println("请输入你的选择");
            Scanner sc = new Scanner(System.in);
            a = sc.nextInt();
            switch (a) {
            case 1:
                ss.yin();

                break;
            case 2:
                ss.yinr();

                break;
            case 3:
                ss.jie();

                break;
            case 4:
                System.out.println("退出成功");
                break;
            default:
                System.out.println("没有这个选项");

            }
        } while (a != 4);
    }
}
复制代码

 

 

 

 

 

posted @   小白学程  阅读(1060)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示