2023-09-27

オブジェクト指向で学ぶ人生

Microsoft本社入り口に貼ってあるらしいコード

時は金なりという意味か?

    public class Person {
        BasicInfo info;
        float stock;
        float Value;
        public string Name(bool isSpy){
            return isSpy ? info.Name : info.Name.ToSecondName();
        }
        public string Sex(bool isNormal){
            return isNormal == info.isMan ? "Man" : "Woman";
        }
        public float Earn(bool isExtra = false){
            float sexPad = info.isMan ? 1f : 0.5f;
            float racePad = info.isWhite ? 1f : 0.5f;
            var delta = DateTime.Now - info.Birth;
            int age = (int)(delta.TotalDays / 365);
            float result = Value * sexPad * racePad * age;
            if(isExtra){
                Value += result;
            }
            return result;
        }
        enum Race{
            White, Black, Yellow
        };
        class BasicInfo{
            public string Name;
            public int NationalId;
            public bool isWhite;
            public bool isMan;
            public DateTime Birth;
            public BasicInfo(string Name, int NationalId, Race race, bool isMan){
                this.Name = Name;
                this.NationalId = NationalId;
                this.isWhite = race == Race.White;
                this.isMan = isMan;
                Birth = DateTime.Now;
            }
        }

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん