第五章

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

namespace Dome1
{
    class Class1
    {
      public string name;
        public string place;
        public int score;
        public double price;
        Class1 [] class1=new Class1[3];
          public void Showinfo() { 
              class1[0]=new Class1();
              class1[0].name="杯子";
              class1[0].place="第一厂库第一排";
              class1[0].score = 108;
              class1[0].price = 17.02;
             
              class1[1] = new Class1();
              class1[1].name = "花瓶";
              class1[1].place = "第一厂库第二排";
              class1[1].score = 99;
              class1[1].price = 10.02;
             
              class1[2] = new Class1();
              class1[2].name = "热水器";
              class1[2].place = "第一厂库第三排";
              class1[2].score = 102;
              class1[2].price = 9.02;
              Console.WriteLine("库存商品清单列表:");
              Console.WriteLine("------------------------");
              for (int i = 0; i < class1.Length; i++) {
                  Console.WriteLine("商品名称:" + class1[i].name);
              }
              Console.WriteLine("------------------------");
          }
          public void Show() {
              Showinfo();
              bool flag=true;
              do
              {
                  Console.WriteLine("=======================欢迎使用库存管理系统=====================");
                  Console.WriteLine("1.根据商品的名称获取商品的位置 2.取得客户满意度最高的货品 3.退出");
                  Console.WriteLine("================================================================");
                  Console.WriteLine("请选择:");
                  int num = int.Parse(Console.ReadLine());
                  switch (num)
                  {
                      case 1:
                          Show1();
                          break;
                      case 2:
                          Show2();
                          break;
                      case 3:
                          flag = false;
                          break;
                      default:
                          Console.WriteLine("输入的货品的名称错误!");
                          break;
                  }
              } while (flag);
          
          }
          public void Show1() {
              Console.WriteLine("请输入货品的名称:");
              string name = Console.ReadLine();
              for (int i = 0; i < class1.Length; i++) { 
                if(name.Equals(class1[i].name)){
                    Console.WriteLine(class1[i].place);
                    break;
                }
                else if (i == class1.Length - 1) {
                    Console.WriteLine("没有找到!");
                }
              }
          }
          public void Show2() {
              int max = 0;
              for (int i = 0; i < class1.Length; i++)
              {
               if(class1[i].score>max){
                   max = class1[i].score;
                   Console.WriteLine("温馨提示:");
                   Console.WriteLine("满意度最高的货品:"+class1[i].name+"摆在:"+class1[i].place+"满意度:"+max+"价格:"+class1[i].price);
                   break;
               }
              }
          }
    }
}

测试类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dome1
{
    class Program
    {
        static void Main(string[] args)
        {
            Class1 v  = new Class1();
            v.Show();
            Console.ReadLine();
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值