某购物网站有多个网店,一个网店有多个会员,每个会员都有其会员账号和会员余额。
请创建网店类和会员类,要求实现以下功能
在网店类中,通过构造函数初始化多个会员对象,并可以通过索引值或会员账号查询或修改会员余额
在会员类中,通过构造函数中初始化会员账号和会员余额;修改会员账号时,要求会员账号必须是3位;查询会员余额时,如果会员余额小于等于0,则返回“无可用金额!”。
请创建网店类和会员类,要求实现以下功能
在网店类中,通过构造函数初始化多个会员对象,并可以通过索引值或会员账号查询或修改会员余额
在会员类中,通过构造函数中初始化会员账号和会员余额;修改会员账号时,要求会员账号必须是3位;查询会员余额时,如果会员余额小于等于0,则返回“无可用金额!”。
创建完网店类0和会员类后,请访问网店类和会员类,初始化多个会员,并查询或修改会员余额
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class wz
{
wd[] wds;
public wz(int capacity)
{
wds = new wd[capacity];
}
public wd[] Wds
{
get { return wds; }
set { wds = value; }
}
}
class wd
{
hy[] hys;
public hy[] Hys
{
get { return hys; }
set { hys = value; }
}
public wd(int capacity)
{
hys = new hy[capacity];
}
public hy this[int capacity]
{
get
{
if (capacity >= 0 && capacity < hys.Length)
{
return hys[capacity];
}
return null;
}
set
{
if (capacity >= 0 && capacity < hys.Length)
{
hys[capacity]=value;
}
}
}
public hy this[string id]
{
get
{
foreach (hy item in hys)
{
if (item.Hid == id)
{
return item;
}
}
return null;
}
set
{
for (int i = 0; i < hys.Length; i++)
{
if (hys[i].Hid == id)
hys[i] = value;
}
}
}
}
class hy
{
string hid;
float balance;
public string Hid
{
get { return hid; }
set
{
if(value.Length==3)hid = value;
}
}
public float Balance
{
get { return balance; }
set
{
if(balance>0)balance = value;
else Console.WriteLine("无可用金额");
}
}
public hy(string hid, float balance)
{
this.hid = hid;
this.balance = balance;
}
}
class Program
{
static void Main(string[] args)
{
wz wzs = new wz(3);
wd wds = new wd(2);
hy hys = new hy("1",1.2f);
wds[0] = hys;
wds["1"].Balance = 9.9f;
Console.WriteLine(wds["1"].Balance);
}
}
}
1.定义猫类,实例化多个猫类的对象,累计白猫和黑猫各多少只
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class cat
{
public static int count1;
public static int count2;
string color;
int id;
public int Id
{
get { return id; }
set { id = value; }
}
public string Color
{
get { return color; }
set { color = value; }
}
public cat(string color)
{
if (color == "white")
{
count1++;
}
if (color == "black")
{
count2++;
}
}
}
public class Program
{
//静态成员 (共有的成员,不能被实例访问,只能通过类名访问)
//静态方法(只能操作静态成员,)
//静态类(静态类的成员也都是静态的,大多是工具类,不可以被实例化)
static void Main(string[] args)
{
cat c1 = new cat("white");
cat c2 = new cat("black");
cat c3 = new cat("white");
cat c4 = new cat("black");
Console.WriteLine("白猫个数:" + cat.count1);
Console.WriteLine("黑猫个数:" + cat.count2);
}
}
}