JAVA实现简单超市收银系统、控制台输入

 

   

 主体

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import cc.lanou.supermarket.com.Commodity;
import cc.lanou.supermarket.com.CommodityImpl;
import cc.lanou.supermarket.test.Information;

public class Supermarket {
    static List<Commodity> users = new ArrayList<Commodity>();

    public static void main(String[] args) {
        coles();
    }

    public static void coles() {
        // 用scanner接受控制台的信息,最后关闭close
        Scanner scanner = new Scanner(System.in);
        // 设置是否有门店信息推出系统
        // 获取时间
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        String str3 = formatter.format(date);
        // 订单编号
        Calendar calendar = Calendar.getInstance();
        int y = calendar.get(Calendar.YEAR);
        int m = calendar.get(Calendar.MONTH);
        int d = calendar.get(calendar.DATE);
        // 订单
        int a = 0;
        String str1 = y + "" + m + "" + d + "0000" + a;
        // 收款机编号
        String str2 = "0371-123456789";
        // System.out.println(str1);
        CommodityImpl ip = new CommodityImpl();
        boolean isLogin = false;
        boolean isLoop = true;
        // 门店信息
        Information information = new Information();
        // 创建门店信息类对象
        // 1.设置门店信息
        while (isLoop) {
            System.out.println("-------欢迎来到美丽不打折超市系统-------");
            System.out.println("1.设置门店信息");
            System.out.println("2.顾客结账");
            System.out.println("3.推出系统");
            //System.out.println(" a" + a);
            // 接收操作
            int bian = scanner.nextInt();
            switch (bian) {
            case 1:
                scanner.nextLine();
                System.out.println("请输入门店名字");
                String strName = scanner.nextLine();
                System.out.println("请输入门店地址");
                String strSite = scanner.nextLine();
                System.out.println("请输入门店联系方式");
                String strRelation = scanner.nextLine();
//            Information information = new Information(strName, strSite, strRelation);
                information.setName(strName);
                information.setSite(strSite);
                information.setRelation(strRelation);
                System.out.println("你的信息录入成功");
                System.out.println("门店名字" + information.getName());
                System.out.println("门店地址" + information.getSite());
                System.out.println("门店联系方式" + information.getRelation());
                if (information.getName() != null) {
                    isLogin = true;
                }
                break;
            case 2:
                if (isLogin == false) {
                    System.out.println("请先设置门店信息");
                    bian = 1;
                    break;
                }
                //购买次数
                int a1 = 0;
                float f1 = 0;
                float f2 = 0;
                float f3 = 0;                
                String str5 = "";                                
                //System.out.println("门店名字" + information.getName());
                boolean bl = true;
                boolean b2 = false;
                while (bl) {
                    System.out.println("1.添加商品 " + "2.付款方式" + "3.收款金额" + "4.生成小票" + "5.回主菜单");
                    System.out.println("请按编号选择功能");
                    int i1 = scanner.nextInt();                
                    switch (i1) {
                    case 1:
                        Commodity commodity = new Commodity();
                        b2 = true;
                        scanner.nextLine();
                        System.out.println("请输入商品名字");
                        String commodityName = scanner.nextLine();
                        System.out.println("请输入商品单价");
                        float commodityPrice = scanner.nextFloat();
                        System.out.println("请输入购买数量");
                        float commodityAmount = scanner.nextFloat();
                        commodity.setName(commodityName);
                        commodity.setPrice(commodityPrice);
                        commodity.setAmount(commodityAmount);
                        f1 += commodityPrice * commodityAmount;
                        commodity.setJin(f1);                    
                        commodity.setXiaoPiao(str5);                        
                        Supermarket.cun(commodity);
                        a1++;
                        break;
                    case 2:
                        if (b2 == false) {
                            System.out.println("请先购买商品");
                            break;
                        }
                        scanner.nextLine();
                        System.out.println("付款方式:" + "1(支付宝)" + "2(微信)" + "3(现金)");
                        String str = scanner.nextLine();
                        if (str.equals("1")) {
                            str5="支付宝";
                        } else if (str.equals("2")) {
                            str5="微信";
                        } else if (str.equals("3")) {
                            str5="现金";
                        }
                        break;
                    case 3:
                        if (b2 == false) {
                            System.out.println("请先购买商品");
                            break;
                        }
                        System.out.println("客户付款金额");
                        f2 = scanner.nextFloat();
                        f3 = f2 - f1;
                        break;
                    case 4:
                        if (b2 == false) {
                            System.out.println("请先购买商品");
                            break;
                        }                        
                        //System.out.println("门店名字" + information.getName());
                        System.out.println("订单编号:" + str1 + (a++));
                        System.out.println("---------------------");
                        System.out.println("欢迎光临" + "  " + "TEL " + str2);
                        System.out.println("商品名 " + " " + "售价 " + " " + "数量 " + " " + "金额  ");
                        // System.out.println(commodity.getName() + commodity.getXiaoPiao());
                        for (Commodity i : users) {
                            System.out.println(i.getName() + " " + i.getAmount() + " " + i.getPrice() + " " + i.getJin());
                        }
                        System.out.println("共计" + a1 + "商品");
                        System.out.println("总金额" + f1);
                        System.out.println(str5+"实付" + f2);
                        System.out.println("找余:" + f3);
                        System.out.println("付款时间" + str3);
                        System.out.println("机器标号" + " " + str2);
                        break;
                    case 5:
                        bl = false;
                    default:
                        break;
                    }
                }
                break;
            case 3:
                isLoop = false;
                break;
            default:
                break;
            }
        }
        System.out.println("已退出");
    }

    public static void cun(Commodity object) {
        users.add(object);
    }

}

创建商品类

package cc.lanou.supermarket.com;
/**
 * 商品类
 * @author CC
 *
 */
public class Commodity {

    private String name;
    private float price;
    private float Amount;
    private float jin;
    private String xiaoPiao;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public float getPrice() {
        return price;
    }
    public void setPrice(float price) {
        this.price = price;
    }
    public float getAmount() {
        return Amount;
    }
    public void setAmount(float amount) {
        Amount = amount;
    }
    public float getJin() {
        return jin;
    }
    public void setJin(float jin) {
        this.jin = jin;
    }
    public String getXiaoPiao() {
        return xiaoPiao;
    }
    public void setXiaoPiao(String xiaoPiao) {
        this.xiaoPiao = xiaoPiao;
    }
    public Commodity(String name, float price, float amount, float jin, String xiaoPiao) {
        super();
        this.name = name;
        this.price = price;
        Amount = amount;
        this.jin = jin;
        this.xiaoPiao = xiaoPiao;
    }
    public Commodity() {
        
    }
    

    
}

创建门店信息类

public class Information {
/**
 * 门店信息
 */
    private String name;
    private String site;
    private String relation;

    public Information() {

    }

    public Information(String name, String site, String relation) {
        super();
        this.name = name;
        this.site = site;
        this.relation = relation;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSite() {
        return site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    public String getRelation() {
        return relation;
    }

    public void setRelation(String relation) {
        this.relation = relation;
    }
    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return this.getName();
    }

}

 

  • 17
    点赞
  • 93
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
这是一个比较宽泛的话题,我可以给您提供一些关于Java控制台和Mysql的基础知识以及如何实现一个简单超市收银系统的建议。 Java控制台Java语言的一个基础功能,可以通过它来进行与用户的简单交互。您可以通过Java的System.in和System.out对象来读取和输出数据。例如,您可以使用Scanner类来读取用户的输入,使用System.out.println()方法来输出文本。 Mysql是一个流行的关系数据库管理系统,可以用于存储和查询数据。您可以使用Java中的JDBC API来连接到Mysql数据库并执行SQL语句。例如,您可以使用PreparedStatement类来执行查询和更新数据的操作。 实现一个简单超市收银系统的方法可以有很多种,以下是一些可能的步骤: 1. 设计数据库结构:您需要设计超市收银系统所需的数据表,例如商品表、顾客表、订单表等。确定每个表的字段和数据类,并设置主键和外键等约束。 2. 编Java代码:使用Java控制台应用程序,可以通过控制台与用户交互。您可以使用Java的Scanner类来读取用户的输入,并将数据存储到Mysql数据库中。 3. 实现基本功能:您可以实现一些基本的功能,例如添加商品、删除商品、查询商品信息等。 4. 实现结算功能:您可以实现结算功能,将顾客所选的商品添加到订单中,并计算总价。 5. 实现报表功能:您可以实现一些报表功能,例如每天的销售额、热门商品等。 这些只是超市收银系统的基本实现方式,具体实现细节需要根据您的具体需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值