Question: JAVA Write DateTest class which includes the main method. The program should create three objects of the Date class and one of them should use

JAVA

Write DateTest class which includes the main method.

The program should create three objects of the Date class and one of them should use the default constructor and the other two use three-parameter constructor.

Print all three dates using toString method.

Change the month, day, and year of one of the dates using set methods, and then use get methods to display the new value of month, day, and year.

Print all three dates again using printDate method. (please include comments) Here is my "date.java" I just need you to help with the test class

package p1;

import java.util.*;

// Date class

class Date {

// month, day, and year as private instance variables.

private int month;

private int day;

private int year;

//default constructor

public Date() {

// set the date to 1/1/2000

this.month = 1;

this.day = 1;

this.year = 2000;

}

// three-parameter constructor will include a given month, day, and year as parameters.

public Date(int month, int day, int year) {

this.month = month;

this.day = day;

this.year = year;

}

// get month

public int getMonth() {

return month;

}

// set month

public void setMonth(int month) {

this.month = month;

}

// get day

public int getDay() {

return day;

}

// set day

public void setDay(int day) {

this.day = day;

}

// get year

public int getYear() {

return year;

}

// set year

public void setYear(int year) {

this.year = year;

}

//toString method to return the date in month/day/year format as a string.

@Override

public String toString() {

return month + "/" + day + "/" + year;

}

//printDate method to print the date in month/day/year format.

public void printDate(){

System.out.println(month + "/" + day + "/" + year);

}

}

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!