Create a class called Date that includes three instance variables - a month (type int), a day (type int) and a year (type int). Provide a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and get method for each instance variable. Provide a method displayDate that displays the month, day and year separated by forward slashes. this class will be used by the test application below:
public class DateTest {
/**
* Creates a new instance of <code>DateTest</code>.
*/
public static void main(String[] args) {
Date date1 = new Date(3, 4, 2010);
System.out.print("the initial date is:");
date1.displayDate();
date1.setMonth(11);
date1.setDay(1);
date1.setYear(2011);
System.out.print("\nDate with new values is: ");
date1.displayDate();
System.out.println();
}
}
That is all given. I then went to code the class Date on the next page as follows:
public class Date {
private int month;
private int day;
private int year;
public Date(int monthValue, int dayValue, int yearValue) {
month=monthValue;
day=dayValue;
year=yearValue;
}
private void setMonth(int month) {
int month;
}
public void getmonth(){
return month;
}
private void setDay(int day) {
int day;
}
public void getDay(){
return Day;
}
public void getYear(){
return year;
}
public void displayDate(){
System.out.printf("%d/%d/%d", month(), day(), year());
}
}
I know I am missing a basic understanding of how to use set and get methods. Can anyone shed some light on how to better answer this question? Thanks so much

New Topic/Question
Reply
MultiQuote












|