C#--interface

iamzxf發表於2015-03-30


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

namespace interfaceDemo
{
    interface IPersonalIncome
    {
        double Income { get; }
        void DisplayIncome();
    }

    class Student : IPersonalIncome
    {
        private string name;
        private double subvention;
        private double scholarship;
        private double grants;

        public Student(string name, double subvention, double scholarship, double grants)
        {
            this.name = name;
            this.subvention = subvention;
            this.scholarship = scholarship;
            this.grants = grants;
        }

        public double Income 
        {
            get 
            {
                return subvention + scholarship + grants;
            }
        }

        public void DisplayIncome()
        {
            Console.WriteLine("{0}是學生,總收入{1}",name,Income);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Student stu = new Student("zxf",100,200,300);
            stu.DisplayIncome();
            Console.ReadLine();
        }
    }
}