• 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

how to return a string in order?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a string called schedule, for example:

schedule = "^14%Paul's house?Group Meeting\n^9%Nutty Professor's Office?Office Hours\n^12%MegaBits?Lunch"

After breaking it up using StringTokenizer, how do I return it into chronological order?

Return the schedule for each day of the week as a String with the appointments listed in chronological order, starting with those for the first day of the week and ending with those for the last day of the week.
The String should have the following format
Sunday:
^14%Paul's house?Group Meeting
Monday:
^9%Nutty Professor's Office?Office Hours
Tuesday:
^12%MegaBits?Lunch
Wednesday:
xxx
Thursday:
xxx
Friday:
xxx
Saturday:
xxx

xxx is the String representation of the schedule for each day. There should be no newline after the last schedule.
Note: if there are no appointments scheduled for a certain day, then that day should not be included in the String. (For example, if there are no appointments scheduled on Tuesday then:
Tuesday:
xxx

should not be included.)
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code that parses the full String could use a StringBuffer to build the final String to return, assuming the input String is in chronological order itself. Your example implied it is, and didn't demonstrate how to show an empty day.

If it's not in order, you can create an intermediate data structure to hold and reorder the appointments. What constitutes an appointment? Write a class to manage that information. You can use the built-in Collection classes (List, Map, Set) to work with your Appointment class.

It will help you more if you try out some techniques, post your code and ask specific questions.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic