Page 1 of 1

Consider the partial Date class below (method signatures and instance variables) which represents a day of the year: pub

Posted: Sat May 14, 2022 7:40 pm
by answerhappygod
Consider The Partial Date Class Below Method Signatures And Instance Variables Which Represents A Day Of The Year Pub 1
Consider The Partial Date Class Below Method Signatures And Instance Variables Which Represents A Day Of The Year Pub 1 (49.21 KiB) Viewed 33 times
Consider the partial Date class below (method signatures and instance variables) which represents a day of the year: public class Date { A value between 1 and 12 private int month; // private int day; // A value between 1 and the last day // of the month public int getMonth() { } // accessor method public void setMonth(int newMonth) { } // mutator method public int getDay() { } // accessor method private int lastDayOfMonth() { } // helper method } It has been suggested the accessor method below be added to the class to return the Date one day later than the given date: public Date getNextDate() { if (day == lastDayOfMonth() { month++; if (month == 12) { month = 1; } day = 1; } else { day++; } return this; } What is wrong with this design? You cannot return this from a method. It uses lastDayOfMonth, a private method of the class. It has the side effect of changing the Date. ОО Since it returns a Date other than this one, the class is not consistent.