• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Reverse string

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to Java. I have completed some basic in Java. I am stuck in this problem. How can I solve this problem in a simple way? I have seen some solutions but those were hard for me.


You have a guest list of the people who registered for their stay at the hotel. There are 4 rooms in the hotel: 1 single room, 2 double rooms and 1 family room for three guests. The guest list consists of 4 lines. Each line contains the name or the names of the guests registered together in one room.

Read the names of the registered guests from the list and output each name in a separate line and in reverse order starting with the last registered guest. Note that the order of the guests registered in each room is undefined.


Sample Input:

Jane Kate
John
Mary Susan Paul
Boris Ann

Sample Output:

Ann
Boris
Paul
Susan
Mary
John
Kate
Jane
 
lowercase baba
Posts: 12933
65
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well...where exactly are you stuck?  Nobody will hand you a solution, but we will help you work through it.

Your best place to start is with pencil and paper.  Start writing out - in English - how you would solve this.  Write it out step by step.  Then, imagine what would happen if you gave those steps to a young child - could then follow them and give you the right answer?  If not, refine, clarify, and expand your steps until they can.

Next, think about individual things you need to do.  For example, at minimum, you need to be able to
a) read from a file
b) parse each line for name
c) organize the names in order somehow
d) print them out (you missed this in your sample output - it says to print them, then print them in reverse order).
e) print them in reverse order

Focus on one part at a time.  I might start with just reading the file, and printing out each line - untouched - just to prove I can read the file.  Each of the above steps should probably be its own method.

When i work on part b, i'd start by creating a literal string to parse.  This method doesn't care HOW you get the string, just that you HAVE a string.  You could even create a bunch of string literals to use for testing...including empty strings, strings with one name, and strings with many names.  Think about what you would pass in, and what it should pass back.

and so on...Start with the above.  write out your ideas.  Start with one tiny piece, write some code, and test it. Then, come back when you have more specific questions.

 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic