Question: Consider the following class definition, written by a novice programmer, that represents a specific working day in a 12-week project period. public class DayAndWeek {
Consider the following class definition, written by a novice programmer, that represents a specific working day in a 12-week project period.
public class DayAndWeek {
public int day; // Day of the Week, Varies from 1-5
public int week; // Week of the Project, Varies from 1-12
};
a) (5p) Provide a code fragment showing a redesigned DayAndWeek class that more appropriately encapsulates the two instance variables day and week.
b) (5p) Provide methods that will enable the two instance variables to be queried and changed .
c) (10p) Incorporate an error-checking routine into your instance variable change methods that prevent data items from assuming invalid values.
d) (5p) Provide a method that will ensure the instance variables day and week will be initialised to default values (1,1) immediately upon creation of a new instance of the class.
ATTENTION: The language is JAVA
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
