库存管理系统 2020-10-28

C#实现库存管理系统

  • Goods类 商品基本属性
  • stcok类 页面调用方法
  • test类 实例化对象 执行stcok类

源码

stcok类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class stock
    {
        Goods [] arr = new Goods[4]; //对象数组实例化Goods类
        public void start()
        {
            bool b = true;
            while (b)
            {
                Console.WriteLine("============欢迎使用库存管理系统==========");
                Console.Write("1.请输入货品名称来搜索货品\t");
                Console.Write("2.获得用户满意度最高的货品\t");
                Console.WriteLine("3.退出系统");
                String a = Console.ReadLine();
                switch (a)
                {
                    case "1":
                        {
                            Searchgoods();
                            break;
                        }
                    case "2":
                        {
                            love();
                            break;
                        }
                    case "3": {
                        Console.WriteLine("退出系统");
                        b = false;
                        break;
                    }
                    default:{
                        Console.WriteLine("非法输入!");
                        b = false;
                        break;
                    }
                }
            }
        }
        public void csh() {
        //初始化商品信息 将商品对象添加到对象数组
            Goods g1 = new Goods();
            g1.name = "杯子";
            g1.address = "1-5-8";
            g1.price = 25;
            g1.Loves = 60;
            arr[0] = g1;

            Goods g2 = new Goods();
            g2.name = "手套";
            g2.address = "6-9-1";
            g2.price = 19;
            g2.Loves = 80;
            arr[1] = g2;

            Goods g3 = new Goods();
            g3.name = "鼠标";
            g3.address = "5-4-2";
            g3.price = 45;
            g3.Loves = 85;
            arr[2] = g3;

            Goods g4 = new Goods();
            g4.name = "怡宝";
            g4.address = "6-3-4";
            g4.price = 3;
            g1.Loves = 2;
            arr[3] = g4;
        }
        public void Searchgoods() {
            //查询货品名字 如果一样打印出货柜信息和货品价格
            Console.Write("请输入您需要的货品:");
            String a = Console.ReadLine();
            for (int i = 0; i < arr.Length; i++) {
                if (a.Equals(arr[i].name))
                {
                    Console.WriteLine("商品名:" + arr[i].name);
                    Console.WriteLine("货柜:" + arr[i].address);
                    Console.WriteLine("商品价格:" + arr[i].price);
                }
            }
        }
        public void love() {
            //数组的长度
            int arr_length = 4;
            //冒泡几轮 范围是 0  1
            for (int i = 0; i < arr_length - 1; i++) {
                //这一轮的有效数据长度是多少
                int useful_length = arr_length - i;
                //这一轮可游走的最大下标是多少?
                int max_idx = useful_length - 2;

                //遍历,让下标游走
                for (int j = 0; j < max_idx; j++) { 
                    //比较大小,小的冒右边

                    if (arr[j].Loves < arr[j + 1].Loves) {
                        Goods temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
            Console.WriteLine("满意度最高的是:"+arr[0].name);
        }
    }
}

Goods类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Goods
    {
        public String name; //商品名称
        public String address;//商品地址
        public int Loves;//满意度
        public int price;//商品价格
    }
}

test类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class test
    {
        static void Main(string[] args)
        {
            stock te = new stock();
            te.csh();
            te.start();
            Console.ReadKey();
        }
    }
}

运行截图

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值