コード例 #1
0
ファイル: Person.cs プロジェクト: Naronrit/MvcWorkshop2
        //public void Marry(Person spouse)
        //{
        //    if (this.GetAge() < 20 || spouse.GetAge() < 20)
        //    {
        //        throw new Exception();
        //    }
        //    //return new Person();
        //}
        public Family Marry(Person spouse)
        {
            if (this.GetAge() < 20 || spouse.GetAge() < 20)
            {
                throw new Exception();
            }
            if (this.Gender == spouse.Gender)
            {
                throw new Exception();
            }
            Family f = new Family();

            return f;
        }
コード例 #2
0
ファイル: Person.cs プロジェクト: surrealist/FamilyTree
        public Family Marry(Person spouse)
        {
            if (this.GetAge() < 20 || spouse.GetAge() < 20) {
            throw new Exception();
              }
              if (this.Gender == spouse.Gender) {
            throw new Exception();
              }

              Family f = new Family();
              this.Family = f;
              spouse.Family = f;

              if (this.Gender == "M") {
            f.Husband = this;
            f.Wife = spouse;
              }
              else {
            f.Husband = spouse;
            f.Wife = this;
              }

              return f;
        }
コード例 #3
0
ファイル: Person.cs プロジェクト: kaoechan/FamilyTree
 public Family Marry(Person spouse)
 {
     if (this.GetAge() < 20 || spouse.GetAge() < 20)
     {
         throw new Exception();
     }
     else if (this.Gender == spouse.Gender)
     {
         throw new Exception();
     }
     else
     {
         Family f = new Family();
         if (this.Gender.ToLower().Equals("m"))
         {
             f.Name = this.Name + spouse.Name;
             f.Husband = this;
             f.Wife = spouse;
         }
         else
         {
             f.Name = spouse.Name + this.Name;
             f.Husband = spouse;
             f.Wife = this;
         }
         this.Family = f;
         spouse.Family = f;
         return f;
     }
 }