Question: My question is Create a class called Date that includes 3 instance variablesa month (type int), a day (type int), and a year (type int).

My question is Create a class called Date that includes 3 instance variablesa month (type int), a day (type int), and a year (type int). Provide a constructor that initializes the 3 instance variables and assumes the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day, and year separated by forward slashes(/). Write a test application named DateTest that demonstrates class Dates capabilities.

My code is

public class Date {

int month;

int day;

int year;

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

this.month = month;

this.day = day;

this.year = year;

}

public int getMonth() {

return month;

}

public void setMonth(int month) {

this.month = month;

}

public int getDay() {

return day;

}

public void setDay(int day) {

this.day = day;

}

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public void displayDate() {

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

}

}

public class DateTest {

public static void main(String[] args) {

Date day = new Date(4,16,2012);

day.displayDate();

System.out.println("Month: " + day.getMonth());

System.out.println("Day: " + day.getDay());

System.out.println("Year: " + day.getYear());

day.setMonth(12);

day.setDay(25);

day.setYear(2011);

day.displayDate();

}

}

This was given when someone previously answered, however this code does not work. Please help

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!