Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OOP-1 question

 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • 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
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9063
12
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Marilyn,

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

 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we ned an emoticon for a head slap!
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic