• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Integrating 2 different classes

 
Greenhorn
Posts: 29
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Date class and Time class. Is it possible to pass Time object inside Date constructor so that toString function gives output as 12/05/2013 06:31:30 ?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

farrukh nadeem wrote:I have a Date class and Time class. Is it possible to pass Time object inside Date constructor so that toString function gives output as 12/05/2013 06:31:30 ?


Well, first off, you're confusing two different things: the contents of your object, and how it's displayed.

But in answer to your question, the answer is: Yes. It's your class, so you can do anything you like with it.

The next question though is: Do you want to? And I'm afraid that without seeing the code for your classes, or knowing how you want them to behave, we simply can't answer that.

Winston
 
Farrukh Nadeem
Greenhorn
Posts: 29
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am following Dietel's Java How to Program...

The Date class is follows:
The Time class is :
Now struck at Main class is:
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

farrukh nadeem wrote:Now struck at Main class is:...


Well that doesn't look like it will work, because you don't have a constructor that takes 6 integers.

What about:
Date date = new Date( 12, 5, 1966, new Time2(11,11,02) );
?

That said, I don't really see the point of including a Time in a Date class. If it was me, I think I'd keep the two completely separate, and add a Timestamp class, that wraps one of each.

Winston
 
Farrukh Nadeem
Greenhorn
Posts: 29
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As already stated I am following Dietel's book. So far, I have not seen Timestamp class till chapter 9. Will work on your example.
Regards
 
Farrukh Nadeem
Greenhorn
Posts: 29
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Date date = new Date( 12, 5, 1966, new Time2(11,11,02) ); "

this gave me date print only. any further suggestions?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

farrukh nadeem wrote:this gave me date print only. any further suggestions?


Well, I already gave you one, but it doesn't seem to follow the edicts of your book (which I'm not familiar with). What exactly do you want "suggestions" about?

Winston
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

this gave me date print only. any further suggestions?




Well first i suggest that you read the javadocs for String.format(), look at the Date.toString() method and let us know what you would expect to be output, given the information from the javadocs.

-steve
 
Farrukh Nadeem
Greenhorn
Posts: 29
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dropped this exercise of the book and moved on. Will see it later.
And thanks for your help.
Regards
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic