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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 31 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply