BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C#代写 | SIT232 Object‐Oriented Development Practical Task 4.2

C#代写 | SIT232 Object‐Oriented Development Practical Task 4.2

本次澳洲代写是C#基础运用的一个Task Assignment

General Instructions

In this practical task, you need to implement a class called MyDate, which models a date instance with values
ranging from January 1, 0001 Anno Domini (Common Era) through December 31, 9999 A.D. (C.E.) in the
Gregorian calendar. The class must contain the following three private integer instance variables:

− _year, whose valid value must be in the range between 1 and 9999;

− _month, whose valid value must be in the range between 1 (i.e., January) and 12 (i.e., December);

− _day, whose valid value must be in the range between 1 and 31 (note that the last day depends on the month
and whether it is a leap year).

For these three variables you are required to perform input validation. The class should also contain the
following three private constants.

− MONTHS enumerates the twelve months of a year and is represented by an array of the following strings: “Jan”,
“Feb”, “Mar”, Apr”, ”May”, ”Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, and “Dec”.

− DAYS enumerates the days of a week and is represented by an array of the following strings: “Sunday”,
“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, and “Saturday”.

− DAYS_IN_MONTHS defines the number of days in each calendar month of a non‐leap year. It is an array of the
following integer numbers: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, and 31.

The following is a list of methods that the MyDate class must implement and make accessible to the user.

− MyDate( int day, int month, int year )
Constructor. Initializes a new instance of the MyDate class and sets the three instance variables to the respective
values given in the input.

− void SetYear( int year )
Mutator method. Assigns the value of year to the instance variable _year. The method first verifies whether
the given value is between 1 and 9999; if not, it must throw an ArgumentOutOfRangeException with the
message “Invalid year!” and ignore the input.

− void SetMonth( int month )
Mutator method. Assigns the value of month to the instance variable _month. The method first verifies whether
the given value is between 1 and 12; if not, it must throw an ArgumentOutOfRangeException with the
message “Invalid month!” and ignore the input.

− void SetDay( int day ):
Mutator method. Assigns the value of day to the instance variable _day. The method first verifies whether the
given value is between 1 and dayMax, where dayMax depends on the current month and whether it is a leap
year for February. If the value of day is out of the valid range for the current values of _month and _year, the
method must throw an ArgumentOutOfRangeException with the message “Invalid day!” and ignore the input.

− void SetDate( int day, int month, int year )
Sets the three instance variables to the respective values given in the input. The method first verifies whether
the input is valid; if not, it must throw an ArgumentOutOfRangeException with the message “Invalid year, month,
or day!” and ignore the input.

− int GetYear( )
Accessor method. Returns the value for the instance variable _year.

− int GetMonth( )
Accessor method. Returns the value for the instance variable _month.

− int GetDay( )
Accessor method. Returns the value for the instance variable _day.

− MyDate NextDay( )
Updates this instance of MyDate to the next day and returns this instance. (As an example, note that the call of
NextDay for 31 Dec 2000 must return 1 Jan 2001.)

− MyDate NextMonth( )
Updates this instance of MyDate to the next month and returns this instance. (As an example, note that the call
of NextMonth for 31 Oct 2012 must return 30 Nov 2012.)

− MyDate NextYear( )
Updates this instance of MyDate to the next year and returns this instance. If the resulting year appears to be
greater than 9999, the method must throw an InvalidOperationException with the message “Year out of
range!” and ignore the expected change. (As an example, note that the call NextYear for 29 Feb 2012 must
return 28 Feb 2013.)

− MyDate PreviousDay( )
Updates this instance of MyDate to the previous day and returns this instance. (As an example, note that the call
of PreviousDay for 1 Jan 2001 must return 31 Dec 2000.)

− MyDate PreviousMonth( )
Updates this instance of MyDate to the previous month and returns this instance. (As an example, note that the
call of PreviousMonth for 31 Oct 2012 must return 30 Sep 2012.)

− MyDate PreviousYear( )
Updates this instance of MyDate to the previous year and returns this instance. If the resulting year appears to
be less than 1, the method must throw an InvalidOperationException with the message “Year out of
range!” and ignore the expected change. (As an example, note that the call PreviousYear for 29 Feb 2012
must return 28 Feb 2011.)

− String ToString( )
Returns a string that represents this instances of the MyDate class. ToString is the major formatting method
in the .NET Framework. It converts an object to its string representation so that it is suitable for display. This
method must return the date stored by this instance as a date string formatted to “xxxday d mmm yyyy”; e.g.,
“Tuesday 14 Feb 2012”.

− bool IsLeapYear( int year )
Static method. Returns true if the given year is a leap year. A year is a leap year if it is divisible by 4 but not by
100, or it is divisible by 400 (wish to know why, see the math behind leap years). Otherwise, the method returns
false.

− bool IsValidDate( int year, int month, int day )
Static method. Returns true if the given year, month, and day constitute a valid date. Assume that year must
be between 1 and 9999, month must be between 1 (Jan) to 12 (Dec), and day must be between 1 and
28|29|30|31 depending on month and whether year is a leap year for February.

− int GetDayOfWeek( int day, int month, int year )
Static method. Returns the day of the week, where 0 stands for Sun, 1 for Mon, …, and 6 for Sat, for the given
date.

bestdaixie

评论已关闭。