class User
{
private string UserName;
private string PassWord;
private int DepositMoney;
private int count = 0;
public string UserName1
{
get
{
return UserName;
}
set
{
UserName = value;
}
}
public string PassWord1
{
get
{
return PassWord;
}
set
{
PassWord = value;
}
}
public int DepositMoney1
{
get
{
return DepositMoney;
}
set
{
DepositMoney = value;
}
}
public int Count
{
get
{
return count;
}
set
{
count = value;
}
}
public User()
{
}
public User(string userName, string passWord, int depositMoney)
{
UserName1 = userName;
PassWord1 = passWord;
DepositMoney1 = depositMoney;
}
public User(int count)
{
this.Count = count;
}
public void SaveMoney(int money)
{
DepositMoney1 += money;
}
public void DrawMoney(int money)
{
if (DepositMoney1 >= money)
{
DepositMoney1 -= money;
}
else if(10000+DepositMoney1<money)
{
Count++;
Console.WriteLine("卡被你刷爆了");
DepositMoney = 10000+1000 * Count;
}
else
{
Console.WriteLine("您透支了{0}元",money-DepositMoney1);
}
}
}
class CreditUser : User
{
private int LineOfCredit = 10000;
public CreditUser(int lineOfCredit)
{
LineOfCredit = lineOfCredit;
}
public CreditUser(string userName, string passWord, int depositMoney)
{
UserName1 = userName;
PassWord1 = passWord;
DepositMoney1 = depositMoney;
}
public int LineOfCredit1
{
get
{
return LineOfCredit;
}
set
{
LineOfCredit = value;
}
}
public void AddLOC()
{
if (Count >=3)
{
LineOfCredit1 += 1000;
Count = 0;
}
}
}
main方法参考代码:
CreditUser user = new CreditUser("张三", "123456", 50000);
user.SaveMoney(20000);
Console.WriteLine(user.DepositMoney1);
user.DrawMoney(75000);//透支了,但没有刷爆
user.DrawMoney(90000);//第一次刷爆
Console.WriteLine("您的当前信用额度为{0}", user.LineOfCredit1);
user.AddLOC();
user.DrawMoney(90000);//第二次刷爆
Console.WriteLine("您的当前信用额度为{0}", user.LineOfCredit1);
user.AddLOC();
user.DrawMoney(90000);//第三次刷爆
Console.WriteLine("您的当前信用额度为{0}", user.LineOfCredit1);
user.AddLOC();
Console.WriteLine("您当前的信用额度为{0}", user.LineOfCredit1);