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];
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;
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();
}
}
}
运行截图