赞
踩
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace five { class Goods { private string name; //货品名称 private string place; //货品位置 private double price; //价格 private int satisfaction;//满意度 public string Name { get { return name; } set { name = value; } } public string Place { get { return place; } set { place = value; } } public double Price { get { return price; } set { price = value; } } public int Satisfaction { get { return satisfaction; } set { satisfaction = value; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace five { class Storage { Goods gaa = new Goods(); Goods[] goo = new Goods[3]; //初始化信息方法 public void Initia() { goo[0] = new Goods(); goo[0].Name = "杯子"; goo[0].Place = "第一仓库第一排"; goo[0].Price = 88.0; goo[0].Satisfaction = 70; goo[1] = new Goods(); goo[1].Name = "花瓶"; goo[1].Place = "第三仓库第二排"; goo[1].Price = 188.0; goo[1].Satisfaction = 190; goo[2] = new Goods(); goo[2].Name = "热水器"; goo[2].Place = "第四仓库第五排"; goo[2].Price = 888.0; goo[2].Satisfaction = 100; } //显示菜单方法 public void show() { do { Console.WriteLine("=======================欢迎使用库存管理系统========================"); Console.WriteLine("1:根据货品名称获取物品位置\t2:取得客户满意度最高得货物\t3:退出"); Console.WriteLine("==================================================================="); Console.Write("请选择:"); int select = int.Parse(Console.ReadLine()); switch (select) { case 1: bool arr = Gain(); if (arr==false) { Console.WriteLine("您输入的货品名称不正确!"); } break; case 2: Statis(); break; case 3: Console.WriteLine("谢谢使用!系统退出!"); break; default: Console.WriteLine("菜单选择错误,请重新输入选项!"); break; } } while (true); } //根据货品名称取得货品名称方法 public bool Gain() { bool yes=false; Console.Write("请输入货品名称:"); string _name = Console.ReadLine(); foreach (Goods item in goo) { if (_name.Equals(item.Name)) { Console.WriteLine(item.Place); yes = true; } else { yes = false; } } return yes; } //获取客户满意度最高的货品方法 public void Statis() { gaa = Sta(); //接收方法返回值对象 Console.WriteLine("温馨提示:"); Console.WriteLine("客户满意度最高的货品:{0}\t摆在:{1}\t满意度:{2}\t价格:{3}",gaa.Name,gaa.Place,gaa.Satisfaction,gaa.Price); } //获取客户满意度最高的货品方法,对象作为返回值类型 public Goods Sta() { gaa.Satisfaction = 0; //初始化满意度为0 foreach (Goods item in goo) { if (item.Satisfaction>gaa.Satisfaction) //循环比较满意度大小 { gaa.Satisfaction = item.Satisfaction; gaa.Name = item.Name; gaa.Place = item.Place; gaa.Price = item.Price; } } return gaa; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace five { class Program { static void Main(string[] args) { Storage all = new Storage(); all.Initia(); all.show(); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。