C#入门经典第八章8.5练习答案

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

namespace ConsoleApplication9
{
     

    interface IHotDrink
    {
     
        void Drink();


        void AddMilk();


        void AddSugar();


        string Milk {
      get; set; }

        string Sugar {
      get; set; }

    
    }



    interface ICup
    {
     
        void Wash();


        void Refill();


        void AddSugar();


        string Color {
      get; set; }

        string Volume {
      get; set; }


    }

    public class CupofTea : ICup, IHotDrink
    {
     
        public string Color
        {
     
            get
            {
     
                return "red";

            }

            set
            {
     
                Color = "red";
            }
        }

 
          
   

        public string Volume
        {
     
            get
            {
     
                return "500ml";
            }

            set
            {
     
                Volume = "500ml";
            }
        }

        string IHotDrink.Milk
        {
     
            get
            {
     
                return "新鲜牛奶";
            }

            set
            {
     
            }
        }

        string IHotDrink.Sugar
        {
     
            get
            {
     
                return "方糖";
            }

            set
            {
     
                
            }
        }

        public void AddMilk()
        {
     
            Console.WriteLine(" Tea add Milk");
        }

        public void AddSugar()
        {
     
            Console.WriteLine(" Tea add Sugar ");
        }

        public void Drink()
        {
     
            Console.WriteLine("drink CupofTea ");
        }

        public void Refill()
        {
     
            Console.WriteLine(" Tea  Refill ");
        }

        public void Wash()
        {
     
            Console.WriteLine(" Tea  Wash ");
        }
    }

    public class CupofCafe : ICup, IHotDrink
    {
     
        public string Color
        {
     
            get
            {
     
                return "blue";


            }

            set
            {
     
                Color = "blue";
            }
        }





        public string Volume
        {
     
            get
            {
     
                return "500ml";
            }

            set
            {
     
                Volume = "500ml";
            }
        }

        string IHotDrink.Milk
        {
     
            get
            {
     
                return "新鲜牛奶";
            }

            set
            {
     
            }
        }

        string IHotDrink.Sugar
        {
     
            get
            {
     
                return "方糖";
            }

            set
            {
     

            }
        }

        public void AddMilk()
        {
     

            Console.WriteLine(" Cafe add Milk");
        }

        public void AddSugar()
        {
     
            Console.WriteLine(" Cafe add Sugar ");
        }

        public void Drink()
        {
     
            Console.WriteLine("drink CupofCaff ");
        }

        public void Refill()
        {
     
            Console.WriteLine(" Cafe  Refill ");
        }

        public void Wash()
        {
     
            Console.WriteLine(" Cafe  Wash ");
        }
    }




    
    class Program
    {
     

        public void Drink(IHotDrink myDrink,ICup myCup) 
        {
     

            myDrink.AddMilk();
            myDrink.Drink();
            myCup.Wash();
        
        }


        static void Main(string[] args)
        {
     

            CupofCafe mycafe = new CupofCafe();

            CupofTea mytea = new CupofTea();

            Program mypro = new Program();


            mypro.Drink(mycafe, mycafe);

            Console.ReadLine();


        }
    }
}

你可能感兴趣的:(C#入门经典第八章8.5练习答案)