Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Thank You and thumps up in advance. 11. Classes and Objects / Each Date object stores a single // month/day such as September 19 /

Thank You and thumps up in advance.

image text in transcribed

11. Classes and Objects / Each Date object stores a single // month/day such as September 19 / This class ignores leap years Suppose that you are provided with a pre-written class Date as described at right. (The headings are shown, but not the method bodies, to save space.) Assume that the fields, constructor, and methods shown are already implemented. You may refer to them or use them in solving this problem if necessary public class Date private int month; private int day Write an instance method named absoluteDay that will be placed inside the Date class to become a part of each Date object's behavior. The absoluteDay method should return the "absolute day of the year" between 1 and 365 represented by the Date object. January l is absolute day #1, January 2 is day #2, , and December 31st is absolute day #365. For example, calling this method on a date representing February 13th should return 44 and calling it on a Date representing September 19th should return 262 / Constructs a date with // the given month and day public Date(int m, int d) / Returns the date's day. public int getDay() Returns the date's month public int getMonth) Suppose the following dates have been declared: / Returns the number of days / in this date's month public int daysInMonth() Date janlnew Date(1, 1) Date jan4 new Date(, 4) Date feb1 = new Date( 2, 1); Date mar10new Date (3, 10); Date sepl9new Date (9, 19); Date dec31new Date (12, 31); /Modifies this date's state /I so that it has moved forward // in time by 1 day, wrapping / around into the next month / or year if necessary // example: 9/19 ->9/20 // example: 9/30 ->10/1 // example: 12/31 -> 1/1 The results of calling your method on the above objects are: Call Returns an1.absoluteDay an4.absoluteDa febl.absoluteDa mar10.absoluteDa public void nextDay) 69 62 sep19.absoluteDay dec31.absoluteDa /7 your method would go here You should not solve this problem by writing 12 if statements, one for each month; this is redundant and poor style. If you solve the problem that way, you will receive at most half credit. Also, your method should not have the side effect of modifying the Date object on which it was called. In other words, when your method is done executing, the values of the fields of the Date object on which it was called should be unchanged. A solution that does so will receive at most half credit. (It's okay for you to modify the object's state temporarily if it helps you solve this problem, but when your method is done executing, the state should be the same as when you started.) Recall that your method is allowed to call other methods on Date objects or construct other objects if you like

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions