Welcome to Dream.In.Code
Become a Java Expert!

Join 150,385 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,162 people online right now. Registration is fast and FREE... Join Now!




Need Help with with error message

 
Reply to this topicStart new topic

Need Help with with error message

Purity86
28 Jan, 2008 - 03:09 PM
Post #1

New D.I.C Head
*

Joined: 28 Jan, 2008
Posts: 35


My Contributions
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 launch
CODE

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
User is offlineProfile CardPM
+Quote Post

outlaw107
RE: Need Help With With Error Message
28 Jan, 2008 - 03:12 PM
Post #2

New D.I.C Head
Group Icon

Joined: 1 Nov, 2007
Posts: 31


My Contributions
For future references, please post your code with "code" at the beginning and "/code" with bracers around both code and /code at the end.

This post has been edited by outlaw107: 28 Jan, 2008 - 03:13 PM
User is offlineProfile CardPM
+Quote Post

GWatt
RE: Need Help With With Error Message
28 Jan, 2008 - 03:24 PM
Post #3

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,360



Thanked: 31 times
Dream Kudos: 500
My Contributions
There is a convention that set methods are void. So a good rule of thumb is everywhere you have a set method, it returns void, ie nothing.
User is offlineProfile CardPM
+Quote Post

Purity86
RE: Need Help With With Error Message
28 Jan, 2008 - 03:31 PM
Post #4

New D.I.C Head
*

Joined: 28 Jan, 2008
Posts: 35


My Contributions
QUOTE(GWatt @ 28 Jan, 2008 - 04:24 PM) *

There is a convention that set methods are void. So a good rule of thumb is everywhere you have a set method, it returns void, ie nothing.


thank you smile.gif the program works now
Sorry for the noob question
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:47PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month