For an assignment I am supposed to write a program translating a text to pig latin, the specs for the assignment are below: Write a program that can read or write a text using pig Latin. The user should select at the beginning if he or she wants to translate to pig Latin or from pig Latin, then the user should give the file name where the text is, and the program should translate it and save it in the pigLatinOutput.txt. The rules for pig Latin are as follows: a)If the string begins with a vowel, add the string �-way� at the end of the string. For example the string �eye� becomes �eye-way�. b)If the string does not begin with a vowel, first add �-� at the end of it. Then rotate the string one character at a time; that is, move the first character of the string to the end of the string, and repeat this process until the first character of the string is a vowel. Then, add the string �ay� at the end. For example the string �there� becomes �ere-thay�. For this program consider that �y� is also a vowel. c)If the string is numeric just add the string �-way� at the end of it. I wrote out a program for it, but I get an incredible number of errors when I try to run it. I'm completely lost, this is a really complicated problem for me and I'm not sure what I should do from here. Any help would be greatly appreciated. [ edited to break apart long unbroken lines and to remove the evil tab character -ds ] [ November 17, 2003: Message edited by: Dirk Schreckmann ]
Hi, let me give you some clues. - 'nextToken' is a method. --> nextToken() - String has no methods 'append' or 'insert'. - The first character in a String is charAt(0). This should make the it a little bit easier, at least for the compiler
You might think about making methods as well. Some ideas which come to mind are - - A method which takes a string and returns an array of two strings. The first string would be the passed in string with the rotation to the first vowel done. The second string would be the front part rotated off. - A method which returns a 'decoded' pig latin word when a pig latin word is passed in. You might be able to simplify some comparison's by converting the comparison character to upper or lower case first. Having methods do some work is a good idea, as it lets you make a method and then test it to be sure it works, before you write more code. As you add more methods, it should be easier to track down where the problems are occuring along the way.
The key to succesful programming is to break a big task into many little tasks. This serves two purposes. First, it lets you test each little task to be sure it is working proerly. Second, it gives you a sense of achievement as you get each little task to work. Trying to do too much and having it fail makes it hard to figure out where you went wrong and can lead to all sorts of frustration. Start small and build up. As an example, here is a method that can handle your first requirement:
[ November 17, 2003: Message edited by: Thomas Paul ]