菜狗日记(c#)

今天写了几道封装题目

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Student s = new Student();
            Student s1 = new Student();
            s.Weight = int.Parse(Console.ReadLine());
            s.Name = String.Format(Console.ReadLine());
            Console.WriteLine("{0}的体重是:{1}", s.Name, s.Weight);
            s1.Weight = int.Parse(Console.ReadLine());
            s1.Name = String.Format(Console.ReadLine());
            Console.WriteLine("{0}的体重是:{1}", s1.Name, s1.Weight);
            s.Bi(s1, s);
            Magicer M = new Magicer();
            M.Mag = int.Parse(Console.ReadLine());
            Console.WriteLine("魔法伤害为:" + M.ATtack());
            M.Soldier = int.Parse(Console.ReadLine());
            Console.WriteLine("战士伤害为:" + M.Attack());
            Car c = new Car();
            c.Print();

        }
    }
}

namespace ConsoleApp2
{
    class Magicer
    {
        private int soldier;
        private int _Mag;
        public int Soldier
        {
            get { return soldier; }
            set { soldier = value; }
        }
        public int Attack()
        {
            return soldier;
        }

        public int Mag
        {
            get { return _Mag; }
            set
            {
                if (value <= 10 && value > 0)
                {
                    _Mag = value;
                }
                else
                {
                    Console.WriteLine("输入1-10的范围!");
                }
            }
        }
        public int ATtack()
        {

            return Mag * 5;

        }

    }
    class Student
    {
        private String name;
        private int weight;

        public String Name
        {
            get { return name; }
            set { name = value; }
        }


        public int Weight
        {
            get { return weight; }
            set { weight = value; }
        }
        public void Bi(Student s1, Student s2)
        {
            if (s1.weight < s2.weight)
            {
                Console.WriteLine("{0}比{1}重", s2.name, s1.name);
            }
            else
            {
                Console.WriteLine("{0}比{1}重", s1.name, s2.name);
            }
        }

    }
    class Car
    {
        private String name;
        private int currentSpeed;
        public void Set(String name)
        {
            this.name = name;
        }
        public String GetName()
        {
            return name;
        }
        public void SetcurrentSpeed(int currentSpeed)
        {
            this.currentSpeed = currentSpeed;
        }
        public int GetcurrentSpeed()
        {
            return currentSpeed;
        }
        public void Print()
        {
            Car c = new Car();//实例化对象
            c.name = String.Format(Console.ReadLine());//输入名字
            c.currentSpeed = int.Parse(Console.ReadLine());//输入速度
            Car c1 = new Car();
            c1.name = String.Format(Console.ReadLine());
            c1.currentSpeed = int.Parse(Console.ReadLine());
            Console.WriteLine("{0}的速度为" + "{1}" + "公里", c.name, c.currentSpeed);//输出车速和车名
            Console.WriteLine("{0}的速度为" + "{1}" + "公里", c1.name, c1.currentSpeed);
        }


    }
}
//class Account//账户
//{
//    private long id;
//    protected double balance;
//    private String password;

//    public long Id
//    {
//        get { return id; }
//        set {id = value; }
//    }

//    public double Balance
//    {
//        get { return balance; }
//        set { balance = value; }
//    }

//    public String Password
//    {
//        get { return password; }
//        set { password = value; }
//    }

//}
//class SavingAccount
//{

//}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值