Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Cattle Drive and the fly likes OOP-1 question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "OOP-1 question" Watch "OOP-1 question" New topic
Author

OOP-1 question

Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 153

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: 9046
    
  10
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: 153

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: 9046
    
  10
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: 153

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: 153

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: 1195
we ned an emoticon for a head slap!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OOP-1 question