trouble writing code

I have to make a program that will take a sentence and make it plural. For example, "The cookie is good" would change to "The cookies are good". A box would have to pop up, where you could type the sentence in, then after you hit "ok", the sentence would change. I am new to writing code so I am very confused. Anything to help would be great. Thanks

Message was edited by:

vogte30

[401 byte] By [vogte30a] at [2007-11-26 18:13:35]
# 1

When you ask questions on a forum you need to provide a good bit of information and you must be specific!

Saying you are confused and "anything to help", are too vague. Ask a specific question like:

"I need to prompt the user to enter a sentence. I thought about using JOptionPane but the dialog does not appear. Here is a SSCCE of my code..."

Before you ask questions look at the tutorials and search google and the forum (more than likely your question has been asked and answered before).

zadoka at 2007-7-9 5:46:42 > top of Java-index,Developer Tools,Java Compiler...
# 2

i used a JOptionPane.showInputDialog to prompt a box for the person to enter a sentence. The next step I used was a text.indexOf("is"). I'm not sure where to go from here. I need to locate the "is" in the sentence, then change it to "are". I also need to add the letter "s" to the end of the second word in the sentence entered. Here is what i have so far:

import javax.swing.JOptionPane;

class Translation

{

public static void main(String[] args)

{

String text, first;

text= JOptionPane.showInputDialog(null,"Type your sentence below");

JOptionPane.showMessageDialog(null, text.indexOf("is"));

vogte30a at 2007-7-9 5:46:42 > top of Java-index,Developer Tools,Java Compiler...
# 3

Instead of indexOf I would suggest using replaceAll for "is" and "are"

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

Is the second word always going to be the one that is pluralized? If not how do you know which words to make plurals.

Regardless, you might need to make use the split() method on String as well.

zadoka at 2007-7-9 5:46:42 > top of Java-index,Developer Tools,Java Compiler...
# 4
The second word is always pluralized. My code is supposed to be basic, using indexOf, substring, length and jOptionPane.
vogte30a at 2007-7-9 5:46:42 > top of Java-index,Developer Tools,Java Compiler...
# 5
Split the String on spaces. This will give you a String array with seperate words at each index. You can then add an "s" to the second one.
CaptainMorgan08a at 2007-7-9 5:46:42 > top of Java-index,Developer Tools,Java Compiler...
# 6

> The second word is always pluralized. My code is

> supposed to be basic, using indexOf, substring,

> length and jOptionPane.

you means:

The seconds word iss always pluralizeds. My codes is supposeds to bes basic, usings indexOf, substrings, length ands jOptionPane.

jwentinga at 2007-7-9 5:46:42 > top of Java-index,Developer Tools,Java Compiler...