Hello, i just started an online course (only way school offered) in java. I am having a hard time with a program and was wondering if anyone could help me out.
My project is:Create a class called Date that includes three pieces of information as instance variables—a month (type int), a day (type int), and a year (type int). Your class should have a constructor that initializes the three instance variables and assumes that 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 Date’s capabilities
Im getting an error message when i compile saying missing return statement on my (set methods)
Here is what i have so far:
CODE
public class Date
{
// Setting Up Instance Variables
private int month;
private int day;
private int year;
// Setting Up Constructor
public Date( int x, int y, int z )
{
month = x;
day = y;
year = z;
} // Ending Constructor
// ******************************SET METHODS*********************************
// Method To set the Month
public int setMonth( int x)
{
month = x;
} // End Method
// Method To set the Day
public int setDay( int y)
{
day = y;
} // End Method
// Method To set the Year
public int setYear( int z)
{
year = z;
} // End Method
// ******************************Get METHODS***************************************
// Method To get the Month
public int getMonth()
{
return month;
} // End Method
// Method To get the Day
public int getDay()
{
return day;
} // End Method
// Method To get the Year
public int getYear()
{
return year;
} // End Method
// ********************************************************************************
****
// Method To Display the Date
public void displayDate()
{
System.out.printf( " %d / %d / %d ", getMonth(), getDay(), getYear() );
} // End Method
}
This next code is the application that i launchCODE
public class DateTest
{
public static void main( String args[] )
{
Date date1 = new Date( 7, 4, 2004 );
System.out.print( "The initial date is: " );
date1.displayDate();
// change date values
date1.setMonth( 11 );
date1.setDay( 1 );
date1.setYear( 2003 );
System.out.print( "\nDate with new values is: " );
date1.displayDate();
System.out.println(); // output a newline
}
}
If you see any other problems with my code, can you give me a heads up. So far the compiler is only giving me this one error message so i think im good.
This post has been edited by Purity86: 28 Jan, 2008 - 03:20 PM