• 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

OOP-1 question

 
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I successfully integrated the classes given from OOP-1 assignment. However, I am looking at the programming part of it and I am struggling to separate the input date.
Here is my way of solving it on paper:

java DaysOld 2002-1-2

I want to separate the number between dashes so I can extract the year, month, day. I can use indexOf to find what the index of every dashes but I cannot find a method under String to get char up to the next dash, then next number to dash, etc.

Can someone help?
Garry
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Garry Ba wrote:I want to separate the number between dashes so I can extract the year, month, day. I can use indexOf to find what the index of every dashes but I cannot find a method under String to get char up to the next dash, then next number to dash, etc.
Garry


I think the method you are looking for may be String.split() ... or you could use indexes and substrings (and substring lengths) ... if you're sure you need to separate those numbers.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that will work but I cannot think of any other idea
Do you have any other suggestions to pull out of a hat?

Garry
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest that you look carefully at the classes you are supposed to use, GDate and JDate
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been staring at those two classes, GDate and JDate, but I do not see a constructor that take String year-month-day. The reason I ask how to separate using '-' dash.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marilyn,

Please disregard my last post/question. It finally hit me in my head. Got it!

 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we ned an emoticon for a head slap!
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic