This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Date Class Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date Class Problems" Watch "Date Class Problems" New topic
Author

Date Class Problems

Rich Nelson
Greenhorn

Joined: Sep 22, 2007
Posts: 15
My teacher has asked us to take the following class file, Date.java:



...and create 2 private date fields, as I have already done:



He then wants us to create two constructors: one as a default constructor, and the other that accepts the start and end dates of the time period as parameters. The problem is, I don't know how I would go about creating these methods.

I have tried:



...but I get an error saying that it must return something. Maybe I'm going about this completely wrong, anyways. Could someone please shed some light on this?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

The class is named Date, so the constructor must also be named Date, not DateSpan. If you call it "DateSpan" then Java thinks it's a method instead of a constructor, and in a method declaration you always need to specify a return type ("void" if the method doesn't return a value).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
wood burning stoves
 
subject: Date Class Problems
 
Similar Threads
how to test the setter methods
Inheritance; Problem with Test class
toSrting() method
Error - ; expected
Custom Date class and Appointment class