Question: QUESTION 1 In this problem, you will create a Date class. A Date object will consist of a year, month and day (this is the

 QUESTION 1 In this problem, you will create a Date class.A Date object will consist of a year, month and day (this

QUESTION 1 In this problem, you will create a Date class. A Date object will consist of a year, month and day (this is the state of a Date object). Your Date class will have two constructors: public Date(){...} // creates a Date object corresponding to the beginning of time // (Jan 1st, 1970) public Date(int year, int month, int day){...} // creates a Date object with the specified values All of the attributes in your class must be private. To allow access to the state of a Date object, your class must provide the following getters and setters: public int getYear(){...} // returns the year of this object public int getMonth(){...} // returns the month of this object public int getDay(){...} // returns the day of this object // all these setters return a reference to this Date object so that // we can do method chaining public Date setYear(int year){...} // sets the year of this object public Date set Month(int month) {...} // sets the year of this object public Date setDay(int day){...} // sets the year of this object Add a toString() method to your class that returns string representations of Date objects in the form "DD/MM/YY" where each of YY, MM and DD are 2-digit numbers with any needed zero-padding. For example, the start of time (see first constructor above) would have the string representation "01/01/70" and the due date of this tutorial would be "11/02/21". To create this format, use the static String.format() method that is described in Section 1.5 of the course textbook. You are overriding the toString() method that you are inheriting from the Object class. Be sure that you write this function as follows: @Override public String toString(){ } The @Override is an annotation that tells the compiler to check that we are overriding an inherited method and not simply overloading an method (i.e., creating a new function with the same name as one that the class already has with a different signature). Textbook Reading: (String.format) Date.java. Date.java > 4 Date 1 public class Date] 2 3 /* add your state (attributes here) 4 /* be sure to make all attributes private */ 5 6 7 /* getters */ 8 public int getYear(){ return @; } 9 public int getMonth(){ return 0; } 10 public int getDay(){ return a; } 11 12 @Override 13 public String toString() { 14 return ""; 15 } 16 17 public Date(){ } 18 19 public Date(int y, int n, int d){ } 20 21 // secret testing program too! Run Debug 22 public static void main(String[] args) { 23 Date di = new Date(); 24 System.out.println("The beginning of time..."); 25 System.out.println(d1); 26 System.out.println(d.getYear()); 27 System.out.println(d.getMonth()); 28 System.out.println(d1.getDay(); 29 d1 = new Date(2021, 02, 11); 30 System.out.println("Now-ish..."); 31 System.out.println(d1); 32 System.out.println(d1.getYear()); 33 System.out.println(d1.getMonth()); 34 System.out.println(d.getDay()); 35 36 } 37 38

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!