• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Date Class Problems

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
BWA HA HA HA HA HA HA! Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic