zoukankan      html  css  js  c++  java
  • C# 你什么让程序员寂寞成酱紫 (男生版 娱乐中学习 抽象类 接口 继承 实现方法 )

    你什么让程序员寂寞成酱紫 (男生版 娱乐中学习 抽象类 接口 继承 实现方法 )

     

    一个家庭 相当于 一个空间,这个空间里 有 很多元素,比如 爱,爱这个抽象事物,可能有很多动作,接吻、交流,对于一个爱,必须有2个人物来实现,这个就是对象。

    抽象类---爱 就是 每个人都可以继承的类,但是他本身 无法实现 对象,爱可以变成一个人吗? 不能(抽象类不可以实例化)

    接口---每个人对于爱的表达 可以是:接吻,交流,ML,但是每个人 交流方式 和接吻方式一样吗?  你要是想拥有爱,肯定会接吻,肯会交流,肯定会ML,这就是与接口的约定,每个人的方式不一样,这个就是 多态。

    普通类---对于一个拥有爱的男人,也就是你继承了 爱的元素,你就会有它的元素。这就是继承

    复制代码
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;

    namespace Family
    {

    /* 2个年轻人,
    * 要想组成一个家庭必须经历
    * Kiss -> talking -> Make love
    * (因人而异顺序改变)
    */

    //爱是每个人都配拥有的
    abstract class Love
    {
    //字段
    protected string boyName;
    protected string girlName;
    protected string girlBeautiful;
    protected int boyAge;
    protected int girlAge;
    //属性
    public string BoyName
    {
    get { return boyName; }
    set { boyName = value; }
    }
    public int BoyAge
    {
    get { return boyAge; }
    set { boyAge = (value >= 18) ? value : 0; }
    }

    public string GirlName
    {
    get { return girlName; }
    set { girlName = value; }
    }
    public int GirlAge
    {
    get { return girlAge; }
    set { girlAge = (value >= 18) ? value : 0; }
    }

    //爱的构造初始化
    public Love(string boyname, int boyage)//如果男人拥有爱
    {
    this.BoyName = boyname;
    this.BoyAge = boyage;

    }
    public Love(string girlname, int girlage, string description)//如果女人拥有爱
    {
    this.GirlName = girlname;
    this.GirlAge = girlage;
    this.girlBeautiful = description;
    }

    }
    //经历(接口)
    interface IExperience
    {
    void Kiss();
    void Talking();
    void MakeLove();

    }

    class Boy : Love, IExperience
    {
    //男生的字段
    private decimal boySalay;
    //男生的属性收入
    public decimal BoySalay
    {
    get { return boySalay; }
    set
    {

    if (value >= 2000)
    {
    boySalay = value;
    }
    if (value < 2000)
    {
    Console.WriteLine("你的收入不够谈恋爱");
    }

    }
    }
    public Boy(string boyname, int boyage, decimal salay)
    : base(boyname, boyage)
    {
    this.BoySalay = salay;
    }
    //接吻
    public void Kiss()
    {
    int status = 10;


    for (int i = 1; i < status; i++,status--)
    {
    Console.WriteLine("第{0}天: 我:我们接吻吧,你愿意吗?", i);
    Console.Write("你:");
    string str = Console.ReadLine();
    if (str.ToUpper() == "YES")
    {
    Console.WriteLine();
    Console.WriteLine("恭喜你");
    return;
    }
    else if(str=="不准")
    {
    Console.WriteLine("我:不放弃...");

    }

    if (status <= 0)
    {
    Console.WriteLine("我:良缘难再");
    }

    }


    }
    //交流
    public void Talking()
    {
    int status = 5;
    for (int i = 0; i < status; i++)
    {
    Console.WriteLine("我:你要分手吗“");
    Console.Write("你:");
    string str = Console.ReadLine();
    if (str.ToUpper() == "YES")
    {
    Console.WriteLine("我:好吧,我是孤独的!");
    return;
    }
    else if(str=="再说")
    {
    Console.WriteLine("我:我懂你意思了。");
    return;
    }
    }
    }

    //Making Love
    public void MakeLove()
    {
    Console.WriteLine("深夜....");
    Console.WriteLine("One Night,one boy and one girl......");
    }
    }


    public class Test
    {
    static void Main()
    {
    Console.WriteLine("[2个年轻人] [要想组成一个家庭必须经历] [Kiss -> talking -> Make love] (因人而异顺序改变) ");
    Console.Write("恋爱进行时");
    for (int i = 0; i < 10; i++)
    {
    Console.Write(".");
    Thread.Sleep(500);
    }
    Console.WriteLine();
    Console.Write("某天,我们能谈恋爱吗?");
    for (int i = 0; i < 10; i++)
    {
    Console.Write(".");
    Thread.Sleep(500);
    }
    Console.WriteLine();

    Boy oneboy = new Boy("jack",20,2000);
    oneboy.Kiss();
    oneboy.Talking();
    oneboy.MakeLove();
    }
    }


    }
    复制代码



     
     
  • 相关阅读:
    病毒侵袭持续中---hdu3065(AC自动机模板)
    病毒侵袭---hdu2896(AC自动机)
    Keywords Search---hdu2222(AC自动机 模板)
    Theme Section---hdu4763(kmp, Next数组的运用)
    Girls' research---hdu3294(回文子串manacher)
    吉哥系列故事——完美队形II---hdu4513(最长回文子串manacher)
    String Boot-thymeleaf使用(四)
    Spring Boot-properties使用(二)
    Spring Boot-springbootHelloword(一)
    redis-运维-redis单机和集群
  • 原文地址:https://www.cnblogs.com/meimao5211/p/3334184.html
Copyright © 2011-2022 走看看