船台租约

来源:互联网 发布:java this 编辑:程序博客网 时间:2024/06/15 19:24

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication72
{
    class AnnualLease : lease
    {
        private DateTime startDate;//起始日期
        public DateTime StartDate
        {
            get { return startDate; }
            set
            {
                startDate = value;
                endDate = startDate.AddDays(period);//终止日期算法与年初不同
            }
        }

        private DateTime endDate;//终止日期
        public DateTime EndDate
        {
            get { return endDate; }
        }

        private int period;//租用时长
        public int Period
        {
            get { return period; }
            set { period = value; }
        }

        private int berthWidth;//船台宽度
        public int BerthWidth
        {
            get { return berthWidth; }
            set
            {
                berthWidth = value;
                switch (berthWidth)
                {
                    case 10: unitPrice = 800; break;  //日租单价与年租不同
                    case 12: unitPrice = 900; break;
                    case 14: unitPrice = 1100; break;
                    default: unitPrice = 0; break;
                }
            }
        }

        private int unitPrice;//单价
        public int UnitPrice
        {
            get { return unitPrice; }
        }

        public AnnualLease() { }//构造函数
        public AnnualLease(int p, DateTime s, int b) //构造函数
        {
            Period = p;
            StartDate = s;
            BerthWidth = b;
        }
        public double Rent() //计算租金
        {
            return unitPrice * period;
        }
        public void Print() //输出
        {
            Console.WriteLine("---------年租船台租约------------------");
            Console.WriteLine("船台规格:{0}", berthWidth);
            Console.WriteLine("租用时长:{0}年", period);
            Console.WriteLine("租约日期:{0:D}-{1:D}", startDate, endDate);
            Console.WriteLine("租金:{0}×{1}={2}", unitPrice, period, Rent());
        }
    }


    class DailyLease : lease
    {
        private DateTime startDate;//起始日期
        public DateTime StartDate
        {
            get { return startDate; }
            set
            {
                startDate = value;
                endDate = startDate.AddDays(period);//终止日期算法与年初不同
            }
        }

        private DateTime endDate;//终止日期
        public DateTime EndDate
        {
            get { return endDate; }
        }

        private int period;//租用时长
        public int Period
        {
            get { return period; }
            set { period = value; }
        }

        private int berthWidth;//船台宽度
        public int BerthWidth
        {
            get { return berthWidth; }
            set
            {
                berthWidth = value;
                switch (berthWidth)
                {
                    case 10: unitPrice = 20; break;  //日租单价与年租不同
                    case 12: unitPrice = 25; break;
                    case 14: unitPrice = 30; break;
                    default: unitPrice = 0; break;
                }
            }
        }

        private int unitPrice;//单价
        public int UnitPrice
        {
            get { return unitPrice; }
        }

        public DailyLease() { }//构造函数
        public DailyLease(int p, DateTime s, int b) //构造函数
        {
            Period = p;
            StartDate = s;
            BerthWidth = b;
        }
        public double Rent() //计算租金
        {
            return unitPrice * period;
        }
        public void Print() //输出
        {
            Console.WriteLine("---------日租船台租约------------------");
            Console.WriteLine("船台规格:{0}", berthWidth);
            Console.WriteLine("租用时长:{0}日", period);
            Console.WriteLine("租约日期:{0:D}-{1:D}", startDate, endDate);
            Console.WriteLine("租金:{0}×{1}={2}", unitPrice, period, Rent());
        }
    }

    class WeekLease : lease
    {
        private DateTime startDate;//起始日期
        public DateTime StartDate
        {
            get { return startDate; }
            set
            {
                startDate = value;
                endDate = startDate.AddDays(period);//终止日期算法与年初不同
            }
        }

        private DateTime endDate;//终止日期
        public DateTime EndDate
        {
            get { return endDate; }
        }

        private int period;//租用时长
        public int Period
        {
            get { return period; }
            set { period = value; }
        }

        private int berthWidth;//船台宽度
        public int BerthWidth
        {
            get { return berthWidth; }
            set
            {
                berthWidth = value;
                switch (berthWidth)
                {
                    case 10: unitPrice = 120; break;  //周租单价与年租不同
                    case 12: unitPrice = 140; break;
                    case 14: unitPrice = 180; break;
                    default: unitPrice = 0; break;
                }
            }
        }

        private int unitPrice;//单价
        public int UnitPrice
        {
            get { return unitPrice; }
        }

        public WeekLease() { }//构造函数
        public WeekLease(int p, DateTime s, int b) //构造函数
        {
            Period = p;
            StartDate = s;
            BerthWidth = b;
        }
        public double Rent() //计算租金
        {
            return unitPrice * period;
        }
        public void Print() //输出
        {
            Console.WriteLine("---------周租船台租约------------------");
            Console.WriteLine("船台规格:{0}", berthWidth);
            Console.WriteLine("租用时长:{0}周", period);
            Console.WriteLine("租约日期:{0:D}-{1:D}", startDate, endDate);
            Console.WriteLine("租金:{0}×{1}={2}", unitPrice, period, Rent());
        }

    }

 

    class lease
    {
        static void Main(string[] args)
        {

            //年租用例
            int yp = 1;
            DateTime ys = new DateTime(2014, 12, 27);
            int yb = 10;
            AnnualLease c1 = new AnnualLease(yp, ys, yb);
            c1.Print();

            //日租用例
            int cp = 15;
            DateTime cs = new DateTime(2014, 12, 27);
            int cb = 14;
            DailyLease c2 = new DailyLease(cp, cs, cb);
            c2.Print();
            //周租用例
            int xp = 1;
            DateTime xs = new DateTime(2014, 12, 27);
            int xb = 12;
            WeekLease c3 = new WeekLease(xp, xs, xb);
            c3.Print();
            Console.ReadKey();
        }
    }
}

总结:刚用数组与重构、触发器等用的不是很好。


   

 

0 0
原创粉丝点击