public void CollectData() { this.FirstName = Collect.PromptForString("First name: "); this.LastName = Collect.PromptForString("Last name: "); this.Age = Collect.PromptForInt("Age: "); this.Sex = Collect.GetSex(); if (this.isMarried()) { this.Spouse = new Person(); this.Spouse.FirstName = Collect.PromptForString("Name of spouse: "); this.Spouse.Age = Collect.PromptForInt("Age: "); } }
public void CollectDataSpouse() { if (Utilities.askSpouse() == "y") { Spouse = new Person(); System.Console.Write("Enter Your Spouse's First Name : "); Spouse.FirstName = System.Console.ReadLine(); Spouse.LastName = this.LastName; System.Console.Write("Enter Your Spouse's Age : "); Spouse.Age = int.Parse(System.Console.ReadLine()); SumOfAllAges += Spouse.Age; HeadCounter++; this.Spouse.Spouse = this; } }
static void Main(string[] args) { Person p1 = new Person(); Person p2 = new Person(); p1.CollectData("p1"); p1.CollectDataSpouse(); p2.CollectData("p2"); p2.CollectDataSpouse(); Utilities.printHeader(); p1.PrintNameAndAge(); if (p1.Spouse != null) { p1.Spouse.PrintNameAndAge(); } p2.PrintNameAndAge(); if (p2.Spouse != null) { p2.Spouse.PrintNameAndAge(); } System.Console.WriteLine(""); System.Console.WriteLine("Average Age: " + Person.GetAverageAge()); System.Console.ReadKey(); }
static void Main(string[] args) { Collect.Greeting(); Person entry1 = new Person(); Person.Count++; entry1.CollectData(); Person.newEntry(); Person entry2 = new Person(); Person.Count++; entry2.CollectData(); Person.newEntry(); Person entry3 = new Person(); Person.Count++; entry3.CollectData(); System.Console.WriteLine("Thank you. Press any key to display results..."); System.Console.ReadKey(); System.Console.Clear(); System.Console.WriteLine("Data for Person #1:"); entry1.PrintData(); System.Console.WriteLine("Data for Person #2:"); entry2.PrintData(); System.Console.WriteLine("Data for Person #3:"); entry3.PrintData(); System.Console.WriteLine("Donnie asked for average age, but I have a question about it and he didn't call me because he was watching a movie.\n"); System.Console.WriteLine("Press any key to exit... "); System.Console.ReadKey(); }