| Author |
OOP-1 question
|
Gary Ba
Ranch Hand
Joined: Oct 23, 2009
Posts: 150
|
|
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
|
star chaser..
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
|
|
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.
|
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
|
 |
Gary Ba
Ranch Hand
Joined: Oct 23, 2009
Posts: 150
|
|
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
Joined: Jul 22, 2000
Posts: 9033
|
|
|
I suggest that you look carefully at the classes you are supposed to use, GDate and JDate
|
 |
Gary Ba
Ranch Hand
Joined: Oct 23, 2009
Posts: 150
|
|
|
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
Joined: Oct 23, 2009
Posts: 150
|
|
Marilyn,
Please disregard my last post/question. It finally hit me in my head. Got it!
|
 |
Carol Murphy
village idiot
Bartender
Joined: Mar 15, 2001
Posts: 1173
|
|
we ned an emoticon for a head slap!
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
|
|
|
 |
 |
|
|
subject: OOP-1 question
|
|
|