Question: Lab1 Problem 1 Date class Suppose you are given a class named Date with the following contents: W A Date stores a month and day
Lab1 Problem 1 Date class Suppose you are given a class named Date with the following contents: W A Date stores a month and day of the (non-leap year public class Date private int month private int day constructs a new Date with the given month day public Date(int m, int d) returns the fields' values public int get Month public int getDay public int days in Monthl) public void nextDay public String toString 1 1. Requirement : Date daysTallxmas Write an instance method days TillXmas that will be placed inside the Date class. The method retums how many days away the Date object is from Christmas December 25, in the same year. For example, Nov. 22 is 33 days away, Sep. 3 is 113 days away. Dec 25 is O days away, and Dec 31 is 6 days away Here is an example call: Date d-new Date(9.3% System.out.println(d.days TillXmax 113 Write a Client program to test your solution 2. Requirement 2: Dateswhiraclerk Write an instance method subtract Wecks that will be placed inside the Date class. The method accepts an integer parameter and shifts the date backward by that many weeks (A week is exactly 7 days.) The date before 1/1 is 12/31 Here are some example calls on a given date object: Dated new Date(9, 19); .d.subtract Weeks): d is now 9/12 d.subtract Wecks(2Wd is now 8/29 Lab1 d. subtract Weeks 5 d is now 725 d.subtract Weeks/20)Wd is now 3/7 d subtract Weeks 110% dis now 126 (2 years prior) Write a Client program to test your solution
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
