說了會再見,最近好嗎?無論你在哪裡>也許你在溫暖的家,或許你在身在異鄉的城市;或許你高高的峰頂放生高歌,或許你還在陡峭的山峰半空努力攀爬.......相信我們都會登上頂峰,"會當凌絕頂,一覽眾山小"..
今天給大家分享===>庫存管理系統
如圖(部分):
01.首先我們得先創建一個倉庫類,定義些屬性>>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Day01
{
public class Goods
{
//神器類
public string name;
public string difang;
public double price;
public double high;
}
}
02.然後我們再創建顧客類>>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Day01
{
public class Custor
{
Goods[] goods = new Goods[3];
public void Initial()
{
//01.數組的值
//1
Goods goods1 = new Goods();
goods1.name = "葵花寶典";
goods1.difang = "天庭";
goods1.price = 1.28;
goods1.high = 90;
goods[0] = goods1;
//2
Goods goods2 = new Goods();
goods2.name = "獨孤九劍";
goods2.difang = "人間";
goods2.price = 3.50;
goods2.high = 90;
goods[1] = goods2;
//3
Goods goods3 = new Goods();
goods3.name = "吸星大法";
goods3.difang = "魔界";
goods3.price = 12.65;
goods3.high = 90;
goods[2] = goods3;
}
public void ShowMenu()
{
//02.輸出神器清單
Console.WriteLine("=====神器清單列表=====>>>");
Console.WriteLine();
foreach (Goods item in goods)
{
if (item != null)
{
Console.WriteLine("商品名稱:{0}", item.name);
Console.WriteLine("=============================");
}
}
}
public void Welcome()
{
Console.WriteLine("=====歡迎使用神器系統=====>>>");
Console.WriteLine("1.根據神器名稱獲取神器地址 2.取得客戶滿意度最高的貨品 3.退出");
Console.WriteLine("請選擇:");
int num = int.Parse(Console.ReadLine());
switch (num)
{
case 1:
//
GetGoodsPlace();
break;
case 2:
Console.WriteLine();
break;
case 3:
Console.WriteLine("退出");
break;
}
}
public void GetGoodsPlace() {
//03.查詢神器位置
bool flag1 = false;
Console.WriteLine("請輸入貨品名稱:");
string name1 = Console.ReadLine();
for (int i = 0; i <goods.Length; i++)
{
if (goods[i].name==name1)
{
flag1 = true;
goods[i].high++;
Console.WriteLine("此神器在:{0}",goods[i].difang);
Console.WriteLine("自動轉換為主頁面==>>");
Welcome();
break;
}
}
if (flag1 == false)
{
Console.WriteLine("沒有此神器!");
Console.WriteLine("自動轉換為主頁面==>>");
Welcome();
}
}
public void GetMaxPleased()
{
//04.獲取客戶滿意度(當滿意度相同的時候)
if (goods[0].high > goods[1].high && goods[1].high >= goods[2].high || goods[0].high >= goods[1].high && goods[1].high > goods[2].high)
{
Console.WriteLine("客戶滿意度最高的貨品:{0}\t擺放在:{1}\t滿意度:{2}\t價格:{3}", goods[0].name, goods[0].difang, goods[0].high, goods[0].price);
}
if (goods[0].high == goods[1].high && goods[1].high == goods[2].high)
{
Console.WriteLine("未能判斷出最高滿意度!他們的滿意度都為:{0}", goods[0].high);
}
if (goods[1].high > goods[0].high && goods[0].high >= goods[2].high || goods[1].high >= goods[0].high && goods[0].high > goods[2].high)
{
Console.WriteLine("客戶滿意度最高的貨品:{0}\t擺放在:{1}\t滿意度:{2}\t價格:{3}", goods[1].name, goods[1].difang, goods[1].high, goods[1].price);
}
if (goods[2].high > goods[0].high && goods[0].high >= goods[1].high || goods[2].high >= goods[0].high && goods[0].high > goods[1].high)
{
Console.WriteLine("客戶滿意度最高的貨品:{0}\t擺放在:{1}\t滿意度:{2}\t價格:{3}", goods[2].name, goods[2].difang, goods[2].high, goods[2].price);
}
if (goods[0].high > goods[2].high && goods[2].high >= goods[1].high || goods[0].high >= goods[2].high && goods[2].high > goods[1].high)
{
Console.WriteLine("客戶滿意度最高的貨品:{0}\t擺放在:{1}\t滿意度:{2}\t價格:{3}", goods[0].name, goods[0].difang, goods[0].high, goods[0].price);
}
}
}
}
02-2大家是不是好麻煩的樣子,有可能你會花好長時間,不要這樣,教你一個簡單的方法(當滿意度不同的時候):
//01.首先先給滿意度goods[i].high賦不同的值
public double GetMaxPleased2()
{
//02.利用冒泡排序找出最大值
for (int i = 0; i < goods.Length-1; i++)
{
for (int j = 0; j <goods.Length-1-i; j++)
{
if (goods[j].high>goods[j+1].high)
{
double temp = goods[j].high;
goods[j].high = goods[j + 1].high;
goods[j + 1].high = temp;
}
}
}
return goods[2].high;//返回最大的值
//03.最後在main方法中接收並輸出.......
}
是不是有種豁然開朗的感覺,不用謝,可能在你們高手的眼裡這都是不值一提的.......見諒吧!
03.最後我們就可以在main方法中調用>>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Day01
{
public class Program
{
static void Main(string[] args)
{
Custor custor = new Custor();
custor.Initial();
custor.ShowMenu();
custor.Welcome();
Console.ReadLine();
}
}
}
謝謝!我親愛的朋友們!如果我有不對的地方或你有好的建議和意見,望賜教喲!
時間有限,下約樓!!!!!!!
QQ:1907832004
E: 5212504881@163.com