hii, can anyone give me any suggestion about how i can make the program below?

Question:
You are to write a program that will take in an arbitrary number of lines of text and output it in Pig Latin. Each line of text will contain one or more words. A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case). Words should be converted to Pig Latin according to the following rules (non-words should be output exactly as they appear in the input):

1.Words that begin with a vowel (a, e, i, o, or u, and the capital versions of these) should just have the string ``ay'' (not including the quotes) appended to it. For example, ``apple'' becomes ``appleay''.

2.Words that begin with a consonant (any letter than is not A, a, E, e, I, i, O, o, U or u) should have the first consonant removed and appended to the end of the word, and then appending ``ay'' as well. For example, ``hello'' becomes ``ellohay''.

3.Do not change the case of any letter.

Sample Input
This is the input.

Sample Output
hisTay isay hetay inputay.
Link: http://online-judge.uva.es/p/v4/492.html

Okay? So what do you have so far, and what problems is it giving you? We are not going to do it for you.

Outline what you need to do first. Raise a few questions and answer them.

You need to address a few things:

  • Identify which parts of the input string are words and which are not and bypass the ones that are not.
  • Separate each word - how would you identify distinct words?
  • Identify the character at the start of the word as a vowel or consonant - how can you do this efficiently and effectively?
  • Copy the first letter if it is a consonant and append it with "ay" at the end of each word - how will you append them?
  • How can this be written concisely and carried out efficiently?

Answer all those questions and figure out what you're going to do each element of the question with. Good planning will make writing your code much, much easier because all you will be doing if you have a very solid outline is filling in the blanks, really.

I would recommend for this that you look at Char and String and get to know them. No one here is going to actually write code for you from scratch but you should post again if you have issues with addressing a certain aspect and want some pointers or suggestions as to how to attack the problem.

http://java.sun.com/javase/6/docs/api/java/lang/String.html
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Character.html

Good luck!

commented: Well written. +21

i didnt ask for whole solution. i only asked suggestion...

thnx a lot for ur suggestion Godstryke...

i didnt ask for whole solution. i only asked suggestion...

And hoped for a complete cut-n-paste ready solution, as does everyone that is not willing to think about things themselves, and so simply post complete assignment texts on a forum.

That statement does not convince me of your honesty or intent. If you really wanted a suggestion and not an at least partial solution, then you should have also stated your thoughts about how you might go about it and/or anything you've written so far in order to show your own efforts and willingness to work.

He could even look at snippets that have been posted on this very forum and learn from them.

http://www.daniweb.com/code/snippet1271.html

That link shows a very basic 'translator' to pig latin.

There are some very helpful people on this forum; however, as masijade said, they are not here to do your work for you. I have found that when I post and show that I am trying to learn it and make progress here and there, they are more than willing to help out.

Godstryke had a good list of what you should do if you aren't sure where to start.

Best of luck :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.