Java---------超市管理系统(完善文件读入)

这个程序实现了简单的超市票务管理系统,包括商品信息读取、购物、结账和打印清单等功能。用户可以开始购物,选择商品并输入购买数量,然后进行结账,系统会根据总价给出不同额度的折扣,并允许用户选择支付方式。此外,还提供了打印商品清单的选项。商品信息存储在Goods.txt文件中,包括商品名称、编号、单价和单位。
摘要由CSDN通过智能技术生成

主类

import java.io.File;
import java.io.FileNotFoundException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Scanner;


public class TickstingManagmentSystem {


    public static void main(String[] args) throws FileNotFoundException {


        //定义超市列表对象数组
        Goods[] goods =new Goods[100];
        //导入文件,文件位置自行修改
        @SuppressWarnings("resource")
        Scanner scanner = new Scanner(new File("D:\\code\\ceshi01\\src\\com\\msq\\Goods.txt"));

        int goodsIndex=0;
        while (scanner.hasNext()){
            String str = scanner.next();
            //分割字符串
            String[] strings = str.split("\\|");

            //填入对应的数值
            //超市商品列表
            goods[goodsIndex] = new Goods();
            goods[goodsIndex].name = strings[0];
            goods[goodsIndex].number = Double.valueOf(strings[1]);
            goods[goodsIndex].price = Double.valueOf(strings[2]);
            goods[goodsIndex].unit =strings[3];

            goodsIndex++;
        }


        double payPrice=0;
        //操作首页
        System.out.println("       超市票务管理系统");
        System.out.println("本超市商品清单如下:");
        System.out.println("----------------------------");
        System.out.println("编号  "+"名称         "+"单价  "+"单位       ");
        // i 商品index
        int i;
        for(i=0;i<goodsIndex;i++)
        {
            System.out.printf("%-1.0f  %-3s  %10.2f  %-3s ",goods[i].number,goods[i].name,goods[i].price,goods[i].unit);
            System.out.println();
        }
        System.out.println("----------------------------");

        //操作类型
        System.out.println("欢迎光临!!!小管 很高兴为您服务^_^");
        System.out.println("祝您购物愉快哟(づ ̄3 ̄)づ╭❤~");
        System.out.println("请选择您的操作:");
        System.out.println("     1.开始购物");
        System.out.println("     2.结账");
        System.out.println("     3.打印商品清单");
        System.out.println("     0.退出系统");

        //输入操作编号
        int n = 0;
        @SuppressWarnings("resource")
        Scanner sc=new Scanner(System.in);
        System.out.printf("请输入操作编号:",n);
        n=sc.nextInt();
        while(n!=0)
        {
            if(n==1)//开始购物
            {
                double  m = 0 ;//购买商品编号
                System.out.printf("请输入你需要购买的商品编号(0退出):",m);
                m=sc.nextDouble();

                for(i=0;m!=0;i++)
                {
                    if(m>goodsIndex+100|m<101)
                        System.out.println("       亲!本店没有该商品呢-_-|| ");
                    else {
                        System.out.println("您选择的商品是:名称:"+goods[(int) (m-101)].name+"  编号:"+(int)goods[(int) (m-101)].number+"  单价: "+goods[(int) (m-101)].price+"  单位:"+goods[(int) (m-101)].unit);
                        System.out.printf("请输入购买数量:",goods[(int) (m-101)].amount);
                        goods[(int) (m-101)].amount=sc.nextDouble();
                        goods[(int) (m-101)].total=goods[(int) (m-101)].price*goods[(int) (m-101)].amount;
                        System.out.println("名称:"+goods[(int) (m-101)].name+"  编号:"+(int)goods[(int) (m-101)].number+"  单价:"+goods[(int) (m-101)].price+"  单位:"+goods[(int) (m-101)].unit+"  数量:"+goods[(int) (m-101)].amount+"  价钱:"+(double)Math.round(goods[(int) (m-101)].total*100)/100);
                    }
                    System.out.printf("请输入你需要购买的商品编号(0退出):",m);
                    m=sc.nextDouble();

                }

            }
            if(n==2)//结账
            {

                System.out.println("------------万德隆超市------------");
                double totalPrice=0;//商品总价
                double totalAmount=0;//商品总数量

                for(i=0;i<goodsIndex;i++)
                {
                    if(goods[i].total!=0)
                    {
                        totalPrice=totalPrice+goods[i].total;
                        totalAmount=totalAmount+goods[i].amount;
                    }
                }
                //折扣
                double totalRedution;
                if(totalPrice>0&totalPrice<=100)
                    totalRedution=0;
                else if(totalPrice>100&totalPrice<=200)
                    totalRedution=totalPrice*0.1;
                else if(totalPrice>300&totalPrice<=300)
                    totalRedution=totalPrice*0.2;
                else {
                    totalRedution=totalPrice*0.3;
                }
                if(totalPrice==0)
                {
                    System.out.println("亲!您还没有购买任何商品奥,请先选择商品哈 ̄ω ̄||");
                }
                else {

                    //实付金额
                    double actualPrice;
                    actualPrice=totalPrice-totalRedution;
                    System.out.println("您一共购买了"+(int)totalAmount+"件商品");
                    //支付方式
                    System.out.println("支付方式有:1.支付宝    2.微信     3.刷卡     4.现金");
                    String way[]={"支付宝","微信","刷卡","现金"};
                    int p=0;
                    System.out.printf("请选择您的支付方式:",p);
                    p=sc.nextInt();
                    System.out.println("您的支付方式为"+"-----"+way[p-1]);
                    //支付金额

                    System.out.printf("您的付款金额为:",payPrice);
                    payPrice=sc.nextDouble();
                    if(payPrice<totalPrice)
                    {
                        System.out.printf("真是抱歉,您付的钱不够呢,请重新输入付款金额:",payPrice);
                        payPrice=sc.nextInt();
                    }
                    System.out.println("您的优惠金额为:"+(double)Math.round(totalRedution*100)/100+"元");
                    System.out.println("您的实付金额为:"+(double)Math.round(actualPrice*100)/100+"元");
                    //找零
                    double changePrice=payPrice-actualPrice;
                    System.out.println("您的找零金额为:"+(double)Math.round(changePrice*100)/100+"元");
                    System.out.println("-------------------------");
                    System.out.println("万德隆超市感谢您的光临^_^");
                }

            }
            if(n==3)//打印商品清单
            {
                if(payPrice==0){
                    System.out.println("亲,需要先结账才能打印商品清单呢~");
                }
                else{
                    double totalPrice=0;//商品总价
                    double totalAmount=0;//商品总数量

                    for(i=0;i<goodsIndex;i++)
                    {
                        if(goods[i].total!=0)
                        {
                            totalPrice=totalPrice+goods[i].total;
                            totalAmount=totalAmount+goods[i].amount;
                        }
                    }
                    //折扣
                    double totalRedution;
                    if(totalPrice>0&totalPrice<=100)
                        totalRedution=0;
                    else if(totalPrice>100&totalPrice<=200)
                        totalRedution=totalPrice*0.1;
                    else if(totalPrice>300&totalPrice<=300)
                        totalRedution=totalPrice*0.2;
                    else {
                        totalRedution=totalPrice*0.4;
                    }

                    //实付金额
                    double actualPrice;
                    actualPrice=totalPrice-totalRedution;
                    //找零
                    double changePrice=payPrice-actualPrice;

                    //打印顶部
                    System.out.println("-------------------------");
                    System.out.println("本人确认以上交易,同意将其计入本卡账户");
                    System.out.println("       万德隆南师店");
                    System.out.println("收银员:1094    "+"收银机号:007");
                    SimpleDateFormat df = new SimpleDateFormat("日期:yyyy-MM-dd 时间:HH:mm:ss");//设置日期格式
                    System.out.println(df.format(new Date(n)));
                    //打印中部
                    System.out.println("-------------------------");
                    System.out.println("商品编号    "+"商品名称"+"   数量"+"*"+"单价"+"          小计");
                    for(i=0;i<6;i++)
                    {
                        if(goods[i].total!=0)
                        {
                            System.out.printf("%-1.0f       %-3s      %5.2f*%5.2f     %5.2f ",goods[i].number,goods[i].name,goods[i].amount,goods[i].price,(double)Math.round(goods[i].total*100)/100);
                            //System.out.println((int)goods[i].number+"    "+goods[i].name+"        "+goods[i].amount+"*"+goods[i].price+"  "+(double)Math.round(goods[i].total*100)/100);
                            System.out.println();
                        }
                    }
                    System.out.println("-------------------------");
                    System.out.println("支付金额:"+payPrice   );
                    System.out.printf("合计金额:%5.2f  总折扣:%5.2f",totalPrice,totalRedution);
                    System.out.println();
                    System.out.println("实付金额:"+actualPrice);
                    System.out.println("找零:"+(double)Math.round(changePrice*100)/100+"元");
                    System.out.println("--------------------------");
                    System.out.println("      请保管好您的购物小票");
                    System.out.println("    购物小票是您退款换货的凭证");
                    System.out.println("   请凭此票到购物台开取发票^_^");
                }

            }

            System.out.println();
            System.out.println("欢迎光临!!!小管 很高兴为您服务^_^");
            System.out.println("祝您购物愉快哟(づ ̄3 ̄)づ╭❤~");
            System.out.println("请选择您的操作:");
            System.out.println("     1.开始购物");
            System.out.println("     2.结账");
            System.out.println("     3.打印商品清单");
            System.out.println("     0.退出系统");
            System.out.printf("请输入操作编号:",n);
            n=sc.nextInt();
        }
        System.out.println("本次服务已结束^_^");
        System.out.println("           欢迎下次光临ヾ(o´∀`o)ノ ");
        System.out.println("您的满意是我们服务的宗旨!!!");
    }
}

商品类

public class Goods {

    String name;//商品名称
    double number;//商品编号
    double price;//商品单价
    String unit;//商品单位
    double amount;//商品数量
    double total;//商品合计
}

文本文件

Goods.txt

牛奶|101|3.0|袋
饼干|102|23.0|盒
苹果|103|3.2|Kg
香梨|104|2.65|Kg
香蕉|105|6.8|Kg
石榴|106|7.2|Kg
橘子|107|5.2|Kg
香肠|108|2.0|
基于struts网上书店 JSP+Access论坛 网络招标信息管理系统 sql2000网络教学平台 mySQL超市管理系统 超市管理系统 教学管理系统 基于网络环境的选课系统 学生信息管理系统 新闻系统 新闻文章发布系统 考试系统 网络教学系统 网上书店系统 问卷管理... www.yateshi.com/service/13519.html 21K 2009-4-8 - 百度快照 求职java方向的web开发! - 程序员/软件工程师 - 58.com 2.熟悉STRUTS结构、MVC的开发;熟练Hibernate数据库持久层的开发及Spring。 3.能熟练应用多种JAVA应用服务器(Tomcat ,...武汉星星超市管理系统(2007-10-2007-12) 项目描述:对超市的货物、员工、财务进行管理 职责:模块开发,系统设计,数据... bj.58.com/tech/35220795x.shtml 11K 2009-2-13 - 百度快照 源码下载列表 - 纽纶网 | Nulung.com 600G IT资料,文档,书籍,... 1568_fjswpic12人气:超市管理系统\\数据库脚本和数据库备份超市管理系统\\数据库脚本和数据库备份-Supermarket ...所属分类:发布日期:2008-10-13文件大小:3845697提供者:StrutsNETBOOK6人气:一款网上书店的J2EE代码,采用STRUTS技术 ... www.dssz.net/100304-size-asc/1249.html 15K 2009-4-21 - 百度快照 新东方一搏职业培训学校 开发基于桌面的J2SE应用系统;(...2、MVC模式、Struts框架 3、...系统分析师。主要研究方向为软件项目管理、软件产品生命...曾主持参与铁路系统多个大型项目设计与开发,如全国铁路货车大修财务清算系统、车号标签自动识别系统、货车检修成本管理... www.hrbrcw.com/job/1920.aspx?jid=5165 53K 2009-4-22 - 百度快照
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值