11章ppt

某购物网站有多个网店,一个网店有多个会员,每个会员都有其会员账号和会员余额。
请创建网店类和会员类,要求实现以下功能
在网店类中,通过构造函数初始化多个会员对象,并可以通过索引值或会员账号查询或修改会员余额
在会员类中,通过构造函数中初始化会员账号和会员余额;修改会员账号时,要求会员账号必须是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);


        }
    }
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值