public static void Main(string[] args) { SimpleDate date = new SimpleDate(13, 2, 2015); Console.WriteLine("Friday of the examined week is " + date); SimpleDate newDate = date.AfterNumberOfDays(7); int week = 1; while (week <= 7) { Console.WriteLine("Friday after " + week + " weeks is " + newDate); newDate = newDate.AfterNumberOfDays(7); week = week + 1; } Console.WriteLine("The date after 790 days from the examined Friday is ... try it out yourself!"); // Console.WriteLine("Try " + date.AfterNumberOfDays(790)); Console.WriteLine(); SimpleDate now = new SimpleDate(13, 2, 2015); SimpleDate afterOneWeek = now; afterOneWeek.Advance(7); Console.WriteLine("Now: " + now); Console.WriteLine("After one week: " + afterOneWeek); }
public static void Main(string[] args) { // Creates a new object with the date as parameters. Prints the ToString representation of the values. SimpleDate date = new SimpleDate(13, 2, 2015); Console.WriteLine("Friday of the examined week is " + date); // Calls a method that creates a clone of the date object called newdate. The parameter passed (7) is used to call another method. SimpleDate newDate = date.AfterNumberOfDays(7); // Prints the new date for every week and creates a new instance of the object each time. int week = 1; while (week <= 7) { Console.WriteLine("Friday after " + week + " weeks is " + newDate); newDate = newDate.AfterNumberOfDays(7); week = week + 1; } // Prints the date after 790 days. Console.WriteLine("The date after 790 days from the examined Friday is ... try it out yourself!"); Console.WriteLine("Try " + date.AfterNumberOfDays(790)); }
public SimpleDate AfterNumberOfDays(int days) { SimpleDate newDate = new SimpleDate(day, month, year); newDate.Advance(days); return(newDate); }
public static void Main(string[] args) { SimpleDate now = new SimpleDate(13, 2, 2015); SimpleDate afterOneWeek = now; afterOneWeek.Advance(7); Console.WriteLine("Now: " + now); Console.WriteLine("After one week: " + afterOneWeek); }
public static void Main(string[] args) { SimpleDate date = new SimpleDate(13, 2, 2015); Console.WriteLine("Friday of the examined week is " + date); SimpleDate newDate = date.AfterNumberOfDays(7); int week = 1; while (week <= 7) { Console.WriteLine("Friday after " + week + " weeks is " + newDate); newDate = newDate.AfterNumberOfDays(7); week = week + 1; } Console.WriteLine("The date after 790 days from the examined Friday is ... try it out yourself!"); Console.ReadKey(); }
// used to check if this date object (`this`) is before // the date object given as the parameter (`compared`) public bool Before(SimpleDate compared) { // first compare years if (this.year < compared.year) { return(true); } // if the years are the same, compare months if (this.year == compared.year && this.month < compared.month) { return(true); } // the years and the months are the same, compare days if (this.year == compared.year && this.month == compared.month && this.day < compared.day) { return(true); } return(false); }