当前位置:编程学习 > C#/ASP.NET >>

新人:c#一个很简单的问题,希望有人帮助!!

定义一个Person类,具有  静态的  公共的   属性 人种(身高,体重,性别,出生日期)
那些需要做验证?
    创建构造函数,可以有0--4参数的构造函数
    具有一个  公共的  方法,打印  该人的  所有  成员变量
    具有一个   静态的 方法,获得  是什么  人种
    具有一个  PaySales()  方法 实现:
    1 有车有房 收入的15%的税收
    2 有房 10%
    3 10000以上的  8%;
    4 10000以下的  5%;
需要传递什么参数?
--------------------编程问答--------------------

   class Person
    {
        public static string Race;


        #region properties...
        private float height;
        public float Height
        {
            get
            {
                return height;
            }
            set
            {
                height = value;
            }
        }

        private float weight;
        public float Weight
        {
            get
            {
                return weight;
            }
            set
            {
                weight = value;
            }
        }

        private Sex 易做图;
        public Sex PersonSex
        {
            get
            {
                return 易做图;
            }
            set
            {
                易做图 = value;
            }
        }

        private DateTime birthDay;
        public DateTime BirthDay
        {
            get
            {
                return birthDay;
            }
            set
            {
                birthDay = value;
            }
        }

        private bool hasHouse;
        public bool HasHouse
        {
            get
            {
                return hasHouse;
            }
            set
            {
                hasHouse = value;
            }
        }

        private bool hasCar;
        public bool HasCar
        {
            get
            {
                return hasCar;
            }
            set
            {
                hasCar = value;
            }
        }

        private double salary;
        public double Salary
        {
            get
            {
                return salary;
            }
            set
            {
                salary = value;
            }
        }

        #endregion


        #region constructors...
        public Person()
            : this(180, 70, Sex.Male, DateTime.Now.AddYears(-23))
        {
        }

        public Person(float height)
            : this(height, 70, Sex.Male, DateTime.Now.AddYears(-23))
        {
        }

        public Person(float height, float weight)
            : this(height, weight, Sex.Male, DateTime.Now.AddYears(-23))
        {

        }

        public Person(float height, float weight, Sex 易做图)
            : this(height, weight, 易做图, DateTime.Now.AddYears(-23))
        {
        }

        public Person(float height, float weight, Sex 易做图, DateTime birthDay)
        {
            this.height = height;
            this.weight = weight;
            this.PersonSex = 易做图;
            this.birthDay = birthDay;
        }
        #endregion

        #region Method...

        /// <summary>
        /// 具有一个  公共的  方法,打印  该人的  所有  成员变量 
        /// </summary>
        public void GetPersonInfo()
        {
            Console.WriteLine("Height :  {0}", this.height);
            Console.WriteLine("Weight :  {0}", this.weight);
            Console.WriteLine("Sex :  {0}", this.PersonSex);
            Console.WriteLine("BirthDay :  {0}", this.birthDay.ToString());
            Console.WriteLine("HasCar? :  {0}", this.hasCar);
            Console.WriteLine("HasHouse? :  {0}", this.HasHouse);
            Console.WriteLine("Salary :  {0}", this.salary);
        }

        /// <summary>
        /// 具有一个  静态的 方法,获得  是什么  人种 
        /// </summary>
        /// <returns></returns>
        public static string GetRace()
        {
            return Race;
        }
        
        /// <summary>
        ///  具有一个  PaySales()  方法 实现:
        /// </summary>
        /// <returns></returns>
        public double PaySales()
        {
            if (hasCar && HasHouse)
            {
                return 0.15 * this.salary;
            }
            if (hasHouse)
            {
                return 0.1 * this.salary;
            }
            if (this.salary >= 10000)
            {
                return 0.8 * salary;
            }
            else
            {
                return 0.5 * salary;
            }

        }

        #endregion


        public enum Sex
        {
            Male,
            Female
        }
    }
--------------------编程问答--------------------
引用 1 楼 ouc_ajax 的回复:
C# codeclass Person
    {publicstaticstring Race;#region properties...privatefloat height;publicfloat Height
        {get
            {return height;
            }set
            {
                hei?-
太有才了 --------------------编程问答-------------------- 哇,2楼大哥回答的好认真啊 --------------------编程问答--------------------
引用 1 楼 ouc_ajax 的回复:

会有异常的,Race未经赋值即被使用...另外Race显而易见地也应该定义为enum... --------------------编程问答-------------------- 对了,这种作业题1楼这是在害楼主不是在帮楼主... --------------------编程问答-------------------- 2楼正解 --------------------编程问答--------------------
引用 4 楼 vrhero 的回复:
引用 1 楼 ouc_ajax 的回复:

 会有异常的,Race未经赋值即被使用...另外Race显而易见地也应该定义为enum...


呵呵,批评的是!
感觉题目出的很有问题...种族定为惊天不合适。

--------------------编程问答--------------------
引用 5 楼 vrhero 的回复:
对了,这种作业题1楼这是在害楼主不是在帮楼主...


呵呵,知道了...
以后不会再回这种了 --------------------编程问答-------------------- 打酱油 --------------------编程问答-------------------- 2楼 严谨啊 呵呵 --------------------编程问答-------------------- dingding --------------------编程问答-------------------- 二楼答得就对 你用他写的试试 一定好用 --------------------编程问答-------------------- 打酱油的 --------------------编程问答-------------------- 我来打醋的,上面打酱油的不怕咸吗? --------------------编程问答-------------------- 呵呵,家里盐没了啊 --------------------编程问答--------------------

Person(int ht,int wt,bool gd,DateTime dt)
{
height=ht;
weight=wt;
gender=gd;
borndate=dt;
}
public static int height;
public static int weight;
public static bool gender;
public static DateTime borndate;

public void Print()
{
Console.WriteLine("---OutPut static memebers---");
Console.WriteLine("height="+height.ToString());
Console.WriteLine("weight="+weight.ToString());
Console.WriteLine("gender="+gender.ToString());
Console.WriteLine("borndate="+borndate.ToString("yyyy-mm-dd"));
Console.WriteLine("----OutPut Over------");
}
public static string GetStaticMemeber()
{
return height.ToString()+"_"+weight.ToString()+"_"+gender.ToString()+"_"+borndate.ToString("yyyy-mm-dd");
}
public void PagSales()
{
swith(key)
case 1:
交纳15%税收;
case 2:
交纳10%税收;
case 3:
交纳8%税收;
case 4:
交纳5%税收;
}

楼猪估计是描述的不清楚,不善于言谈跟表达。
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,