using System;
using System.Collections;
namespace StopStation
{
/// <summary>
/// 检验
/// </summary>
class CheckInfor
{
public static bool ifPaiLiang(int pailiang)
{
if (pailiang<10 ||pailiang>100)
{
return false;
}
else
{
return true;
}
}
public static bool ifSudu(int sudu)
{
if (sudu < 10 || sudu > 100)
{
return false;
}
else
{
return true;
}
}
public static bool ifzhuangxiou(string zhuanxiu)
{
if (zhuanxiu.Equals("差"))
{
return false;
}
else
{
return true;
}
}
}
enum CarClass
{
货车,轿车,面包车
}
enum Station
{
已出,未出
}
class Program
{
static void Main()
{
Worke wor = new Worke();
bool isgoon = true;
Console.WriteLine("请输入要选择的种类:1进车;2出车;'N'表示退出");
string input=Console.ReadLine();
input = input.ToLower();
while (isgoon)
{
switch (input)
{
case "1":
wor.AddCar();
break;
case "2":
wor.DellCar();
break;
case "3":
break;
default:
break;
}
}
}
}
class Worke
{
ArrayList carinfor;
public ArrayList Carinfor
{
get { return carinfor; }
set { carinfor = value; }
}
public
void ShowInfor()
{
if (carinfor==null)
{
Console.WriteLine("现在停车场还没有停过车!");
}
else
{
Console.WriteLine("车类
车号
车主名
状态
排量
速度
装修");
foreach (object o in carinfor)
{
try
{
Car c = (Car)o;
if (c.Cc == CarClass.货车)
{
HuoChe hc = (HuoChe)c;
Console.WriteLine(hc.Cc.ToString() + "
" + hc.Carnumber + "
" + hc.Ownername + "
" + hc.Sta.ToString() + "
" + hc.Pailiang.ToString());
}
else if (c.Cc == CarClass.轿车)
{
JiaoChe jc = (JiaoChe)c;
Console.WriteLine(jc.Cc.ToString() + "
" + jc.Carnumber + "
" + jc.Ownername + "
" + jc.Sta.ToString() + "
" +jc.Shudu.ToString());
}
else if (c.Cc == CarClass.面包车)
{
MianBaoChe mb = (MianBaoChe)c;
Console.WriteLine(mb.Cc.ToString() + "
" +mb.Carnumber + "
" + mb.Ownername + "
" + mb.Sta.ToString() + "
" + mb.Zhuanxiu.ToString());
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
public void AddCar()
{
bool ifContinue = true ;
string input;
while (ifContinue)
{
Console.WriteLine("请出入您想添加车的种类,种类有,货车,轿车,面包车三种,按n退出本次操作");
input = Console.ReadLine();
input = input.ToLower();
switch (input)
{
case "货车":
HuoChe hc = new HuoChe();
hc.Cc = CarClass.货车;
bool add=IfHuoche(ref hc);
if (add)
Console.WriteLine("添加完成!");
else Console.WriteLine("添加不成功!");
break;
case "轿车":
JiaoChe jc=new JiaoChe();
jc.Cc=CarClass.轿车;
ifjiaoche(ref jc);
break;
case "面包车":
MianBaoChe mb = new MianBaoChe();
mb.Cc = CarClass.面包车;
ifmianbao(ref mb);
break;
case "n":
ifContinue = false;
break;
default:
Console.WriteLine("您的输入又误!您的输入是:"+input+'\n');
break;
}
}
}
public void DellCar()
{
Console.WriteLine("--------------");
if (carinfor == null)
{
Console.WriteLine("停车场现在没有车");
}
else
{
Console.WriteLine("请输入要出车辆的车牌号");
string input = Console.ReadLine();
bool rigthput = Worke.Juge10(input);
if (rigthput)
{
foreach (object o in carinfor)
{
Car dellCar = (Car)o;
if (dellCar.Carnumber == input)
{
carinfor.Remove(dellCar.Carnumber);
Console.WriteLine("删除成功");
}
}
}
else
{
Console.WriteLine("车牌号必须是一个5位号的数字");
}
}
}
bool IfHuoche(ref HuoChe hc)
{
bool ifrigth = false;
bool ifContinue = true;
while (ifContinue)
{
Console.WriteLine("请输入车的排量,输入n退出本次添加!");
string input=Console.ReadLine();
if (input.ToLower()=="n")
{
ifContinue = false;
}
else if (int.Parse(input) >= 10 && int.Parse(input) <= 100)
{
hc.Pailiang = Int32.Parse(input);
Console.WriteLine("请输入您的车牌号!");
string carname = Console.ReadLine();
bool name = Worke.Juge10(carname);
if (name)
{
hc.Carnumber = carname;
Console.WriteLine("请输入您的姓名!");
hc.Ownername = Console.ReadLine();
if (carinfor == null)
{
carinfor = new ArrayList();
}
Car c = (Car)hc;
carinfor.Add(c);
ifrigth = true;
continue;
}
else
{
Console.WriteLine("您的必须是5位的号码!");
}
}
else
{
Console.WriteLine("您的排量超标,不能进!");
}
}
return ifrigth;
}
bool ifjiaoche(ref JiaoChe jc)
{
bool ifrigth = false;
bool ifContinue = true;
while (ifContinue)
{
Console.WriteLine("请输入车的速度,输入n退出本次添加!");
string input = Console.ReadLine();
if (input.ToLower() == "n")
{
ifContinue = false;
}
else if (int.Parse(input) > 0 && int.Parse(input) < 60)
{
jc.Shudu = Int32.Parse(input);
Console.WriteLine("请输入您的车牌号!");
string carname = Console.ReadLine();
bool name = Worke.Juge10(carname);
if (name)
{
jc.Carnumber = carname;
Console.WriteLine("请输入您的姓名!");
jc.Ownername = Console.ReadLine();
if (carinfor == null)
{
carinfor = new ArrayList();
}
Car c = (Car)jc;
carinfor.Add(c);
ifrigth = true;
}
else
{
Console.WriteLine("您的必须是5位的号码!");
}
}
else
{
Console.WriteLine("您的速度超标,不能进入!");
}
}
return ifrigth;
}
bool ifmianbao(ref MianBaoChe mb)
{
bool ifrigth = false;
bool ifContinue = true;
while (ifContinue)
{
Console.WriteLine("请输入车的车体装修情况(只能输入 :优 良 差),输入n退出本次添加!");
string input = Console.ReadLine();
bool check = CheckInfor.ifzhuangxiou(input);
if (input.ToLower() == "n")
{
ifContinue = false;
}
else if (check)
{
mb.Zhuanxiu = input;
Console.WriteLine("请输入您的车牌号!");
string carname = Console.ReadLine();
bool name = Worke.Juge10(carname);
if (name)
{
mb.Carnumber = carname;
Console.WriteLine("请输入您的姓名!");
mb.Ownername = Console.ReadLine();
if (carinfor == null)
{
carinfor = new ArrayList();
}
Car c = (Car)mb;
carinfor.Add(c);
ifrigth = true;
}
else
{
Console.WriteLine("您的必须是5位的号码!");
}
}
else
{
Console.WriteLine("您的装修情况不符合规定,不能进入!");
}
}
return ifrigth;
}
public static bool Juge10(string b)
{
bool istwonumber = true;
if (b.Length != 5)
{
istwonumber = false;
}
else
{
string j;
int k;
for (int i = b.Length - 1; i >= 0; i--)
{
if (!char.IsLetter(b[i]))
{
j = b[i].ToString();
k = Convert.ToInt32(j);
if (k >= 0 && k <= 9)
{ continue; }
else
{
istwonumber = false;
break;
}
}
else istwonumber = false;
}
}
return istwonumber;
}
}
class Car
{
/// <summary>
/// 类型
/// </summary>
protected CarClass cc;
internal CarClass Cc
{
get { return cc; }
set { cc = value; }
}
protected string carnumber;
public string Carnumber
{
get { return carnumber; }
set { carnumber = value; }
}
protected string ownername;
public string Ownername
{
get { return ownername; }
set { ownername = value; }
}
protected Station sta=Station.未出
;
public Station Sta
{
get { return sta; }
set { sta = value; }
}
}
class HuoChe:Car
{
int pailiang;
public int Pailiang
{
get { return pailiang; }
set { pailiang = value; }
}
}
class JiaoChe:Car
{
int shudu;
public int Shudu
{
get { return shudu; }
set { shudu = value; }
}
}
class MianBaoChe:Car
{
string zhuanxiu;
public string Zhuanxiu
{
get { return zhuanxiu; }
set { zhuanxiu = value; }
}
}
}