Authentication.cs
using System;
using System.Threading;
namespace day0908.EXP1
{
class Authentication
{
const string password = "hello";
//密文显示
public static void secretInput(ref string input)
{
char key;
//ASCII(Enter)= 13
while ((int)(key = Console.ReadKey(true).KeyChar) != 13)
{
input += key;
Console.Write("*");
}
Console.WriteLine();
}
//密码检测
public static bool Check()
{
Console.WriteLine("请输入登录密码:");
string input = String.Empty;
secretInput(ref input);
int count = 0;
while (count < 3 && !input.Equals(password))
{
Console.WriteLine("密码错误,请重新输入(剩余次数{0})", 3 - count);
count++;
//防止输入累加
input = String.Empty;
secretInput(ref input);
}
if (input.Equals(password))
{
Console.WriteLine("登录成功!正在跳转...");
Thread.Sleep(2000);
return true;
}
else
{
Console.WriteLine("错误次数已达上限,正在退出...");
return false;
}
}
}
}
Car_Base.cs
using System;
namespace day0908.EXP1
{
public abstract class Car_Base
{
public string name;
public double price;
}
public class Car_carryPerson:Car_Base
{
//最大承载人数
public double limitCount;
}
public class Car_carryGoods :Car_Base
{
//最大承载重量(吨)
public double limitWeight;
}
public class Car_carryGoodsPerson : Car_Base
{
//最大承载人数
public double limitCount;
//最大承载重量(吨)
public double limitWeight;
}
}
Car_List.cs
using System;
namespace day0908.EXP1
{
//奥迪A4
public class Car_carryPerson_1 :Car_carryPerson
{
public Car_carryPerson_1()
{
name = "奥迪A4";
price = 500;
limitCount = 4;
}
}
//马自达6
public class Car_carryPerson_2 : Car_carryPerson
{
public Car_carryPerson_2()
{
name = "马自达6";
price = 400;
limitCount = 4;
}
}
//金龙(客车)
public class Car_carryPerson_3 : Car_carryPerson
{
public Car_carryPerson_3()
{
name = "金龙";
price = 800;
limitCount = 20;
}
}
//松花江
public class Car_carryGoods_1 :Car_carryGoods
{
public Car_carryGoods_1()
{
name = "松花江";
price = 400;
limitWeight = 4;
}
}
//依维柯
public class Car_carryGoods_2 : Car_carryGoods
{
public Car_carryGoods_2()
{
name = "依维柯";
price = 1000;
limitWeight = 20;
}
}
//皮卡雪6
public class Car_carryGoodsPerson_1 : Car_carryGoodsPerson
{
public Car_carryGoodsPerson_1()
{
name = "皮卡雪6";
price = 450;
limitCount = 4;
limitWeight = 2;
}
}
}
Car_Factory.cs
using System;
namespace day0908.EXP1
{
public enum carType
{
奥迪A4=1,
马自达6,
金龙,
松花江,
依维柯,
皮卡雪6
}
class Car_Factory
{
public static void showALLCar()
{
int listLength = Enum.GetValues(typeof(carType)).Length;
Console.WriteLine("您可租用的类型及其价目表:");
string[] list = new string[listLength];
list[0] = "1. " + (carType)1 + "\t500元/天\t" + "载人:4人";
list[1] = "2. " + (carType)2 + "\t400元/天\t" + "载人:4人";
list[2] = "3. " + (carType)3 + "\t800元/天\t" + "载人:20人";
list[3] = "4. " + (carType)4 + "\t400元/天\t" + "载货:4吨";
list[4] = "5. " + (carType)5 + "\t1000元/天\t" + "载货:20吨";
list[5] = "6. " + (carType)6 + "\t450元/天\t" + "载人:4人\t载货:2吨";
foreach (string i in list)
{
Console.WriteLine(i);
}
}
public static Car_Base getCar(int carNumber)
{
switch (carNumber)
{
case (1):
return new Car_carryPerson_1();
case (2):
return new Car_carryPerson_2();
case (3):
return new Car_carryPerson_3();
case (4):
return new Car_carryGoods_1();
case (5):
return new Car_carryGoods_2();
case (6):
return new Car_carryGoodsPerson_1();
default:return new Car_carryGoodsPerson_1();
}
}
}
}
Car_Lease.cs
using System;
using System.Collections;
namespace day0908.EXP1
{
class Car_Lease
{
public static void leaseCar()
{
Console.WriteLine("请输入您要租汽车的数量:");
int number = Convert.ToInt16(Console.ReadLine());
double totalPrice = 0;
double totalPerson = 0;
double totalWeight = 0;
ArrayList personCar = new ArrayList();
ArrayList goodsCar = new ArrayList();
if (number <= 20 && number > 0)
{
for(int i = 0; i < number; i++)
{
Console.WriteLine("请输入第{0}辆车的序号:",i+1);
int car_id = Convert.ToInt16(Console.ReadLine());
totalPrice += Car_Factory.getCar(car_id).price;
if (Car_Factory.getCar(car_id) is Car_carryPerson) {
Car_carryPerson a0 = Car_Factory.getCar(car_id) as Car_carryPerson;
totalPerson += a0.limitCount;
personCar.Add(car_id);
}
else if(Car_Factory.getCar(car_id) is Car_carryGoods)
{
Car_carryGoods a1 = Car_Factory.getCar(car_id) as Car_carryGoods;
totalWeight += a1.limitWeight;
goodsCar.Add(car_id);
}
else
{
Car_carryGoodsPerson a1 = Car_Factory.getCar(car_id) as Car_carryGoodsPerson;
totalPerson += a1.limitCount;
totalWeight += a1.limitWeight;
personCar.Add(car_id);
goodsCar.Add(car_id);
}
}
}
Console.WriteLine("请输入租车天数:");
int day = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("***可载人的车有:");
foreach(int i in personCar)
{
Console.WriteLine("【"+(carType)(i) + "】");
}
Console.WriteLine("【总载人:{0}人】", totalPerson);
Console.WriteLine("\n***可载货的车有:");
foreach (int i in goodsCar)
{
Console.WriteLine("【"+(carType)(i) + "】");
}
Console.WriteLine("【总载货:{0}吨】", totalWeight);
Console.WriteLine("\n***租车总价格:{0}元", totalPrice*day);
}
}
}
Flash.cs
using System;
namespace day0908.EXP1
{
class Flash
{
//根据登陆状况实现转场效果
public static bool flash(bool checkResult)
{
if (checkResult){
Console.Clear();
//......
return true;
}
else{return false;}
}
}
}
Optimize.cs
using System;
using System.Text;
namespace day0908.EXP1
{
class Optimize
{
//修改控制台信息
public static void loginOptimize()
{
Console.Title = "用户登录";
}
public static void systemOptimize()
{
Console.Title = "租车系统";
}
}
class str
{
private string str1 { set; get; }
public str(string data) { str1 = data; }
/*二元运算符的参数之一必须是包含类型*/
/*用户定义的运算符“str.operator *(str, int)”必须声明为 static 和 public*/
public static String operator *(str a, int b)
{
StringBuilder temp = new StringBuilder();
for (int i = 0; i < b; i++)
{
temp.Append(a.str1);
}
return temp.ToString();
}
}
}
Run.cs
using System;
namespace day0908.EXP1
{
class Run
{
static void Main()
{
Optimize.loginOptimize();
if (!Flash.flash(Authentication.Check())) { return; }
else
{
Optimize.systemOptimize();
Car_Factory.showALLCar();
Console.WriteLine(new str("*")*60);
Car_Lease.leaseCar();
}
Console.ReadLine();
}
}
}